Ok here's the scenario;

I have an upload system which works and uploads image files to a folder called 'upload'.

I also have a homepage.

I want to be able to display the latest file that has been uploaded on the homepage.

How can I achieve this?

Thanks :)

Seems simple enough. If you keep track of the name of the latest file (in a database or a flat file), then you get that name and insert it as an <img statement into the appropriate place on your home page (assuming that it's in PHP or that you can make it a PHP module). You could use a standard file name in the home page if you always copied the latest file to a standard name (over-writing the previous one). The problem with that is if you have different file types (jpg, png etc) then it is no longer standard and it would only work if you converted the format (which of course increases the complexity of the solution).

Member Avatar for rajarajan2017

Yes, have a textfile to write the names of the images or name of the image last uploaded by overwriting the name.

<?php 

// set file to write
$file = '..\library/para.txt'; 
// open file 
$fh = fopen($file, 'w') or die('Could not open file!'); 
// write to file 
$nam='imagename';
fwrite($fh, $nam) or die('Could not write to file'); 
// close file 
fclose($fh); 
?>

Then read the file to identify the latest image name

<?php 
// set file to read
$file = '..\library\para.txt' or die('Could not open file!'); 
// open file handle
$fh = fopen($file, 'r') or die('Could not open file!'); 
// read file contents 
$data = fread($fh, filesize($file)) or die('Could not read file!'); 
// close file 
fclose($fh); 
// print file contents 
echo $data; 
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.