2

So I have a page containing PHP that will take multiple images, then save and display them.

<?php 
if(isset($_POST['submit'])){

// Count total files
$countfiles = count($_FILES['file']['name']);

 echo "<br>";

// Looping all files
for($i=0;$i<$countfiles;$i++){
$filename = $_FILES['file']['name'][$i];
    echo '<img src="upload/'.$filename.'" height=200>';

// Upload file
move_uploaded_file($_FILES['file']['tmp_name'][$i],'upload/'.$filename);        }
echo "<br>";
echo "<h3>Now that you have uploaded your photos, please arrange them and submit them</h3";
    } 
?>

Problem is, I have another page where I would like to use just the ones that have been just uploaded. What can I use to add these to the other page? Bare in mind that the PHP is written so that it echos the image then moves the images from temp storage into a directory that has hundreds of other images so it needs to be taken ideally from somewhere like here echo '<img src="upload/'.$filename.'" height=200>'; so that it isn't random.

Tibrogargan
  • 4,508
  • 3
  • 19
  • 38
WhatsThat
  • 57
  • 7
  • You have to store image path in database and in another page you can fetch image path from database and show it there. – Bhavin Jul 11 '18 at 16:01
  • Is there no way of avoiding having a database? – WhatsThat Jul 11 '18 at 16:02
  • 1
    By building static .html pages with the burned in image path. But thats worse than using a database. Well... you could do it without a database using hundreds of flatfiles that contain image paths... but seriously, you are doing yourself more work than just using a db. – IncredibleHat Jul 11 '18 at 16:03
  • @WhatsThat I am not sure why you do not want to use a database, but you could use file creation timestamp to organize and filter the ones uploaded on last minute or so, check this answer: https://stackoverflow.com/questions/4401320/php-how-can-i-get-file-creation-date – Eduardo Jul 11 '18 at 16:13
  • You could try storing the file path in a session variable (or cookie), but then it's really only available for a short while, and to the person that uploaded it. Otherwise, you would need to use a database to keep track of the file paths. – JPark Jul 11 '18 at 16:33

0 Answers0