Jump to content

Link to uploaded files


fatmart

Recommended Posts

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!!!!

 

Link to comment
Share on other sites


$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]

Link to comment
Share on other sites

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.