Padgoi Posted January 8, 2009 Share Posted January 8, 2009 Hi, I have this very short php query that is simply calling up all uploaded files in a folder. Here is the snippet: <? if($uploaded_files == "") echo " <tr> <td colspan=\"2\" style=\"background: #fff; color: #000; text-align: center\"><br /><strong>There are no uploaded files.</strong><br /><br /></td> </tr> "; else echo $uploaded_files ?> The problem is, when it is echoing the $uploaded files, it is displaying ALL of the files from the folder. I only want to show the very latest upload in that folder, only one (1), not all of them. How would I go about doing this? I appreciate any help. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/140053-calling-up-only-the-most-recent-upload-from-a-folder/ Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 How are you reading the data into $uploaded_files ? Link to comment https://forums.phpfreaks.com/topic/140053-calling-up-only-the-most-recent-upload-from-a-folder/#findComment-732770 Share on other sites More sharing options...
Padgoi Posted January 8, 2009 Author Share Posted January 8, 2009 A few more snippets from the other file: $upload_directory = "files/"; $upload_uri = $folder_directory."/files/"; And later in the file: $open = opendir($upload_directory); $uploaded_files = ""; while($file = readdir($open)) { if(!is_dir($file) && !is_link($file)) { $uploaded_files .= " <tr> <td style=\"background: #fff; color: #000; text-align: left; width: 70%\"><a href=\"$upload_directory$file\" title=\"$file (".filesize($upload_directory.$file)." bytes)\">".$file."</a> (".filesize($upload_directory.$file)." bytes)</td>"; if($allow_file_deletion) $uploaded_files .= " <td style=\"background: #fff; color: #000; text-align: right; width: 30%\"><a href=\"?delete=$upload_directory".urlencode($file)."\" title=\"Delete File\">Delete File</a></td>"; else $uploaded_files .= " <td style=\"background: #fff; color: #000; text-align: right; width: 30%\"></td>"; $uploaded_files .= " </tr> <tr> <td colspan=\"2\" style=\"background: #eee; color: #000; text-align: left; text-indent: 20px\">Uploaded <strong>".date("F d, Y / h:ia", filemtime($upload_directory.$file))."</strong></td>"; $uploaded_files .=" </tr> "; } } function upload_file($upload_directory, $upload_uri) { $file_name = $_FILES["userfile"]["name"]; $file_name = str_replace(" ","_",$file_name); $file_path = $upload_directory.$file_name; $temporary = $_FILES["userfile"]["tmp_name"]; $result = move_uploaded_file($temporary, $file_path); if(!chmod($file_path,0777)) $message = "ERROR: A folder to place the files was not found, or the files need to be CHMODed to 777."; else $message = ($result)?"File has been uploaded." : "An error has occurred."; return $message; } Link to comment https://forums.phpfreaks.com/topic/140053-calling-up-only-the-most-recent-upload-from-a-folder/#findComment-732776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.