Guest User

Untitled

a guest
Dec 15th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. //////// Html code add into abc.php
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="UTF-8">
  6. <title>Single Upload Form with PHP</title>
  7. </head>
  8. <body>
  9.  
  10. <form method="POST" action="upload.php" enctype="multipart/form-data">
  11. <label for="file"> Pick a file : </label>
  12. <input type="file" name ="file1">
  13. Add Watermark :
  14. <input type="file" name ="file2">
  15. <input type="submit" value = "Upload">
  16. </form>
  17. </body>
  18. </html>
  19.  
  20. //////////// add into upload.php php code
  21.  
  22. <?php
  23. //Check if the file is well uploaded
  24. if($_FILES['file1']['error'] || $_FILES['file2']['error'] > 0) { echo 'Error during uploading, try again'; }
  25.  
  26. //We won't use $_FILES['file']['type'] to check the file extension for security purpose
  27.  
  28. //Set up valid image extensions
  29. $extsAllowed = array( 'jpg', 'jpeg', 'png', 'gif' );
  30.  
  31. //Extract extention from uploaded file
  32. //substr return ".jpg"
  33. //Strrchr return "jpg"
  34.  
  35. $extUpload = strtolower( substr( strrchr($_FILES['file1' ]['name'] , '.') ,1) ) ;
  36. $extUpload1 = strtolower( substr( strrchr($_FILES['file2' ]['name'] , '.') ,1) ) ;
  37. //Check if the uploaded file extension is allowed
  38.  
  39. if (in_array($extUpload, $extsAllowed, $extUpload1) ) {
  40.  
  41. //Upload the file on the server
  42.  
  43. $name = "./{$_FILES['file1']['name']}";
  44. $name1 = "./{$_FILES['file2']['name']}";
  45. $result = move_uploaded_file($_FILES['file1']['tmp_name'], $name);
  46. $result1 = move_uploaded_file($_FILES['file2']['tmp_name'], $name1);
  47. if($result){echo "<img src='$name'/>";}
  48.  
  49. else { echo 'File is not valid. Please try again'; }
  50.  
  51. if($result1){echo "<img src='$name1'/>";}
  52.  
  53. } else { echo 'File is not valid. Please try again'; }
  54. ?>
Add Comment
Please, Sign In to add comment