fatmart Posted January 29, 2008 Share Posted January 29, 2008 Hi. I have a script for uploading files to a page where there's links to download them. Problem is, each time I upload a new file, the old ones aren't there anymore. I want a list of all the files I uploaded with a link for each one so I can download them. Someone in this forum provided me this code to get the list of all the files in the folder: <?php if($handle = opendir('class.upload_0.25/test/')) //EDIT TO YOUR DIRECTORY { while(false !== ($file = readdir($handle))) { if(($file == ".") || ($file == "..")){}else { $files .= "<tr> <td> $file </td> </tr>\n"; } } closedir($handle); } echo "<table> $files </table>"; ?> Here's the script to upload the files: $files = array(); foreach ($_FILES['my_field'] as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $files)) $files[$i] = array(); $files[$i][$k] = $v; } } foreach ($files as $file) { $handle = new Upload($file); if ($handle->uploaded) { $handle->Process("./test/"); if ($handle->processed) { echo '<fieldset>'; echo ' <legend>file uploaded with success</legend>'; echo ' <p>' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB</p>'; echo ' link to the file just uploaded: <a href="test/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>'; echo '</fieldset>'; } else { echo '<fieldset>'; echo ' <legend>file not uploaded to the wanted location</legend>'; echo ' Error: ' . $handle->error . ''; echo '</fieldset>'; } } else { echo '<fieldset>'; echo ' <legend>file not uploaded on the server</legend>'; echo ' Error: ' . $handle->error . ''; echo '</fieldset>'; } } What I want to do is kinda merge both of the script to get what I want.. If anyone got any clues, it would help me a bunch!!!! Quote Link to comment https://forums.phpfreaks.com/topic/88308-link-to-uploaded-files/ Share on other sites More sharing options...
amites Posted January 29, 2008 Share Posted January 29, 2008 I might recommend http://us2.php.net/tut.php or the job board, could probably hire someone rather cheap to get that working for you Quote Link to comment https://forums.phpfreaks.com/topic/88308-link-to-uploaded-files/#findComment-452034 Share on other sites More sharing options...
legohead6 Posted January 29, 2008 Share Posted January 29, 2008 $dir = "members/$user/$f3"; $dh = opendir($dir); //get files in the folder while (false !== ($filename = @readdir($dh))) { $files[] = $filename; } $re = array_search('..', $files); $rem = array_search('.', $files); unset($files[$rem], $files[$re]); $totalp = count($files); echo "<tr><Td colspan=3><hr></td></tr><tr><td colspan=4><p align=center><u>Current Files In $folders11 Folder</u></p></td></tr>"; foreach($files as $id => $file){ $folder1=explode('.',"$file"); if(isset($folder1[1])){ $file1 = str_replace(" ", "_", "$file"); $file2 = str_replace(".", ".", "$file1"); if(empty($_GET['f'])){//to find out which directory link to use $doc=@base64_encode($file); $file3 = @str_replace("_"," ", "$file"); echo "<tr><td bgcolor=#B4B4B4><p align=center><a href=\"#\" onClick=\"poptastic('doc.php?f=$doc');\">$file3</p></td><td bgcolor=#B4B4B4>"; echo "<a href=move.php?f=$doc&fo=$folde>Move File</a></td><td bgcolor=#B4B4B4><a href=move.php?f=$doc&d=1>Delete File</a></td><td bgcolor=#B4B4B4><a href=sfile.php?f=$doc>Send File</a></td></tr>"; }[code] heres a code directly from my site that does just that... change the variables and try it[/code] Quote Link to comment https://forums.phpfreaks.com/topic/88308-link-to-uploaded-files/#findComment-452039 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.