Advertisement
AlaminSakib

PHP File Upload

Feb 28th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>
  5.         Forms
  6.     </title>
  7. </head>
  8. <body>
  9.     <h3>Henlo</h3>
  10.     <?php
  11.    
  12.         if(isset($_POST['upload']))
  13.         {
  14.             //var_dump($_FILES);
  15.             if($_FILES['image']['type'] == 'image/jpeg' ) // to restrict type of files to be accepted
  16.             {
  17.                 $tmp = $_FILES['image']['tmp_name']; //directory of the uploaded image
  18.                 //$img_name = $_FILES['image']['name']; //name of the uploaded image
  19.                 $img_name = uniqid().".jpg"; //gives each uploaded file a unique name so that they may not collide
  20.                 move_uploaded_file($tmp, "photos/".$img_name); //upload(the temporary directory that was create when file uploaded, the destiantion)
  21.             }
  22.             else echo "Not supported";
  23.         }
  24.     ?>
  25.     <form method="POST" action="" enctype="multipart/form-data">
  26.         <input type="file" name="image" accept="image/*"><br>
  27.         <!-- type can be the type of input such as button(type is submit), dropdown etc -->
  28.         <!--name is the name of the attribute that will be used in php-->
  29.         <!-- value is the name that will be displayed on the button or input -->
  30.         <input type="submit" name="upload" value="upload">
  31.  
  32.     </form>
  33.  
  34.  
  35. </body>
  36. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement