daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Feb 11th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <form action="upload.php" method="post" enctype="multipart/form-data">
  2.     <input type="file" name="file1">
  3.         <br/>
  4.     <input type="submit" value="Upload">
  5.   </form>
  6.    
  7. <?php
  8. $tmp_name = $_FILES['file1']['tmp_name'];
  9. $path = getcwd() . DIRECTORY_SEPARATOR . 'images';
  10. $name = $path . DIRECTORY_SEPARATOR . $_FILES['file1']['name'];
  11. $success = move_uploaded_file($tmp_name, $name);
  12. if($success) {
  13.     $upload_message = $name . ' has been uploaded.';
  14.     echo "$upload_message";
  15. } else {
  16.     echo "something went wrong :(";
  17. }
  18. ?>
  19.    
  20. <?php
  21. error_reporting(-1);
  22.  
  23. $uploaddir = './images/';
  24.  
  25. // Check for upload attempt
  26. if(isset($_FILES['file1'])){
  27.     $uploadfile = $uploaddir.basename($_FILES['file1']['name']);
  28.  
  29.     // If no error
  30.     if($_FILES['file1']['error'] == 0){
  31.         //Attempt to move
  32.         if (move_uploaded_file($_FILES['file1']['tmp_name'], $uploadfile)) {
  33.             echo "File is valid, and was successfully uploaded.";
  34.         }else{
  35.             echo 'Error moving file.';
  36.         }
  37.     } else {
  38.         // Has error
  39.         $errors = array(0=>'OK',
  40.                         1=>'UPLOAD_ERR_INI_SIZE',
  41.                         2=>'UPLOAD_ERR_FORM_SIZE',
  42.                         3=>'UPLOAD_ERR_PARTIAL',
  43.                         6=>'UPLOAD_ERR_NO_TMP_DIR',
  44.                         7=>'UPLOAD_ERR_CANT_WRITE',
  45.                         8=>'UPLOAD_ERR_EXTENSION'
  46.                         );
  47.         echo "Error: ".$errors[$_FILES['file1']['error']];
  48.     }
  49. }
  50.    
  51. <?
  52. $uploadpath = '../images/';
  53.  
  54. if ($_FILES["file1"]["error"] > 0)
  55.     {
  56.     echo "Return Code: " . $_FILES["file1"]["error"] . "<br />";
  57.     }
  58.  
  59.   else
  60.     {
  61. echo "Upload: " . $_FILES["file1"]["name"] . "<br />";
  62.     echo "Type: " . $_FILES["file1"]["type"] . "<br />";
  63.     echo "Size: " . ($_FILES["file1"]["size"] / 1024) . " Kb<br />";
  64.     echo "Temp file: " . $_FILES["file1"]["tmp_name"] . "<br />";
  65.     }
  66.  
  67.     if (file_exists($uploadpath . $_FILES["file1"]["name"]))
  68.       {
  69.       echo $_FILES["file"]["name"] . " already exists. ";
  70.       }
  71.     else
  72.       {
  73.       move_uploaded_file($_FILES["file"]["tmp_name"],
  74.       $uploadpath . $_FILES["file"]["name"]);
  75.       echo "UPLOAD SUCCESS!";
  76.       }
  77.  
  78. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top