Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Uploading via PHP
  2. <?php
  3.     if ((($_FILES["file"]["type"] == "image/gif")
  4.     || ($_FILES["file"]["type"] == "image/jpeg")
  5.     || ($_FILES["file"]["type"] == "image/jpg")
  6.     || ($_FILES["file"]["type"] == "image/pjpeg"))
  7.     && ($_FILES["file"]["size"] < 512)) {
  8.       if ($_FILES["file"]["error"] > 0) {
  9.             echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  10.         } else {
  11.             echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  12.             echo "Type: " . $_FILES["file"]["type"] . "<br />";
  13.             echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  14.             echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
  15.  
  16.         if (file_exists("upload/" . $_FILES["file"]["name"])) {
  17.             echo $_FILES["file"]["name"] . " already exists. ";
  18.         } else {
  19.             move_uploaded_file($_FILES["file"]["tmp_name"],
  20.             "upload/" . $_FILES["file"]["name"]);
  21.             echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  22.         }
  23.       }
  24.     } else {
  25.         echo "Invalid file";
  26.     }
  27. ?>
  28.        
  29. <form action="upload_file.php" method="post" enctype="multipart/form-data">
  30.     <input type="text" name="title" id="title" maxlength="50" size=40">
  31.     <input type="file" name="file" id="file" />
  32.     <textarea name="comments" maxlength="3000" cols="30" rows="12"></textarea>
  33.     <input type="image" src="/Images/upload_button.png" name="submit" value="Submit" />
  34. </form>