Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <?php
  2. // Configuration - Your Options
  3. $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg'); // These will be the types of file that will pass the validation.
  4. $max_filesize = 1000000; // Maximum filesize in BYTES (currently 0.5MB).
  5. $upload_path = './images/uploaded_images/'; // The place the files will be uploaded to (currently a 'files' directory).
  6. $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
  7. $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
  8.  
  9. // Check if the filetype is allowed, if not DIE and inform the user.
  10. if ( ! in_array($ext, $allowed_filetypes))
  11. die('The file you attempted to upload is not allowed.');
  12.  
  13. // Now check the filesize, if it is too large then DIE and inform the user.
  14. if (filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
  15. die('The file you attempted to upload is too large.');
  16.  
  17. // Check if we can upload to the specified path, if not DIE and inform the user.
  18. if ( ! is_writable($upload_path))
  19. die('You cannot upload to the specified directory, please CHMOD it to 777.');
  20.  
  21. // Upload the file to your specified path.
  22. if (move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
  23. echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
  24. else
  25. echo 'There was an error during the file upload. Please try again.'; // It failed :(.
  26. ?>
  27.  
  28. $upload_path = './images/uploaded_images/';
  29.  
  30. $files = scandir($upload_path);
  31. foreach($files as $filename) {
  32. if(is_image($filename)) {
  33. echo "<div class='gallery-image'><img src='{$filename}'/></div>";
  34. }
  35. }
  36.  
  37. function is_image($filename) {
  38. $image_extensions = array('jpg', 'jpeg', 'png', 'gif');
  39. $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
  40. return in_array($ext, $image_extensions);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement