Advertisement
lowheartrate

question

Mar 14th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. I have just setup a fileupload.php so that I can upload files but am interesting in having the files instantly be setup on the page that I want it with the css that I assign. Is there a way to do this? I would like to have three columns of photos that viewers can see as I upload the files so I do not have to manually add it into the code every single time I want to add a photo to the page.
  2.  
  3. I already know how to make a grid with the photos but am really interested in how to actually have all the photos uploaded to the page to instantly be placed on that grid.
  4.  
  5. My *graphics.php* page :
  6.  
  7. <?php include 'includes/header.php' ?>
  8.  
  9.  
  10.  
  11. <div class="graphics_content">
  12. <div class="page_top_image">
  13. <img src="includes/img/heartfx_graphics.png" class="img-responsive" alt="Responsive image">
  14. </div>
  15. </div>
  16.  
  17. <div class="photo_upload">
  18. <div class="photo_upload_form">
  19. <form action="upload.php" method="post" enctype="multipart/form-data">
  20. Select image to upload:
  21. <br>
  22. <input type="file" name="fileToUpload" id="fileToUpload">
  23. <br>
  24. <input type="submit" value="Upload Image" name="submit">
  25. </form>
  26. </div>
  27. </div>
  28.  
  29.  
  30.  
  31. <?php include 'footer.php' ?>
  32.  
  33. My *upload.php* page :
  34.  
  35. <?php
  36. $target_dir = "uploads/";
  37. $target_file = $target_dir .basename($_FILES["fileToUpload"]["name"]);
  38. $uploadOK = 1;
  39. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  40. //Check if image file is an actual image or a fake image
  41. if(isset($_POST["submit"])) {
  42. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  43. if($check !== false) {
  44. echo "File is an image - " . $check["mime"] . ".";
  45. $uploadOK = 1;
  46. } else {
  47. echo "File is not an image.";
  48. $uploadOK = 0;
  49. }
  50. }
  51.  
  52. // Check if file already exists
  53. if (file_exists($target_file)) {
  54. echo "Sorry, file already exists.";
  55. $uploadOK = 0;
  56. }
  57.  
  58. // Check file size
  59. if ($_FILES["fileToUpload"]["size"] > 500000) {
  60. echo "Sorry, your file is too large.";
  61. $uploadOK = 0;
  62. }
  63.  
  64. // Allow certain file formats
  65. if($imageFileType != "png") {
  66. echo "Sorry, only PNG files are allowed.";
  67. $uploadOK = 0;
  68. }
  69.  
  70. // Check if $uploadOK is set to 0 by an error
  71. if ($uploadOK == 0) {
  72. echo "Sorry, your file was not uploaded.";
  73. // If everything is ok, try to upload file
  74. } else {
  75. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  76. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  77. } else {
  78. echo "Sorry, there was an error uploading your file.";
  79. }
  80. }
  81.  
  82. ?>
  83.  
  84. Thank you in advance for any help. If anything is needed from my code that you would like me to provide I can do so.
  85.  
  86. Best regards,
  87. Codi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement