Jump to content

Recommended Posts

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!

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;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.