Using the script below, I am trying to generate a hyperlink that when clicked on or right-clicked on, will enable the user to download the files that are contained within the specified directory.
However, when I attempt to open the page that contains the script, I get the following error message:
Warning: filesize(): Stat failed for content/documents/upload_files/Resource id #17 (errno=2 - No such file or directory) in /home/public_html/content/documents/doc_002.php on line 96
Warning: fread(): supplied argument is not a valid stream resource in /home/public_html/content/documents/doc_002.php on line 96
Warning: fclose(): supplied argument is not a valid stream resource in /home/public_html/content/documents/doc_002.php on line 98
<?php
$current_dir = "content/documents/upload_files";
$dir = opendir($current_dir);
while (false !== ($file = readdir($dir))) {
if($file == $doc_name) {
if ($file != "." && $file != "..") {
$f4view = fopen("$current_dir/$file", "rb");
$f4view = fread("$current_dir/$f4view", filesize("$current_dir/$f4view"));
echo "<a href=\"content/documents/upload_files/$f4view\">$f4view</a><br>";
fclose("$current_dir/$f4view");
}
}
}
closedir($dir);
?>
Any suggestions?
revez2002