Advertisement
apl-mhd

File upload

Sep 12th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <form action="upload.php" method="post" enctype="multipart/form-data">
  6.     Select image to upload:
  7.     <input type="file" name="file" >
  8.    <button name="submit" type="submit">Upload</button>
  9. </form>
  10.  
  11. </body>
  12. </html>
  13.  
  14.  
  15. /*file upload script php*/
  16.  
  17.  
  18. <?php
  19. if(isset($_POST["submit"])){
  20.     $file = $_FILES["file"];
  21.     print_r($file)."<br>";
  22.  
  23.     $fileName = $_FILES["file"]["name"];
  24.     $tempeName = $_FILES["file"]["tmp_name"];
  25.     $fileError = $_FILES["file"]["error"];
  26.     $fileType = $_FILES["file"]["type"];
  27.  
  28.     $filExt = explode(".",$fileName);
  29.     print_r($filExt);
  30.     $fileActualExt = strtolower(end($filExt));
  31.  
  32.     $allowed =array('jpg','jpeg','png');
  33.  
  34.     if(in_array($fileActualExt,$allowed)){
  35.  
  36.         if($fileError == 0){
  37.  
  38.             $fileNameNew = uniqid('   ',true). ".".$fileActualExt;
  39.             $fileDest = 'img/'.$fileNameNew;
  40.  
  41.             move_uploaded_file($tempeName, $fileDest);
  42.  
  43.  
  44.  
  45.         }
  46.         else
  47.             echo "error";
  48.  
  49.  
  50.     }
  51.     else
  52.     {
  53.         echo "you can't upload";
  54.     }
  55.  
  56.  
  57. }
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement