Hello all,
I am very new to PHP, basically have been looking into it for about a week. I currently have a file directory script that I would like to modify but I have not been able to find the information on what function I need to use.
The directory listing uses the following code to allow the user to download a file.
if($GET['download'] && $forcedownloads) {
$file = str_replace('/', '', $GET['download']);
$file = str_replace('..', '', $file);
if(file_exists($leadon . $file)) {
header("Content-type: application/x-download");
header("Content-Length: ".filesize($leadon . $file));
header('Content-Disposition: attachment; filename="'.$file.'"');
readfile($leadon . $file);
die();
}
}
I would like to have the script redict the user to the same path within a predefined URL. For example if the file lives in /pics/photo.jpg, and the user chooses to click on the file displayed, I would like them rediected to http://192.168.1.1:8000/pics/photo.jpg.
I also see within the code the following which maybe the point at which I would "inject" the URL:
$filename = $files[$i];
if(strlen($filename)>43) {
$filename = substr($files[$i], 0, 40) . '...';
}
$fileurl = $leadon . $files[$i];
if($forcedownloads) {
$fileurl = $_SESSION['PHP_SELF'] . '?dir=' . urlencode($leadon) . '&download=' . urlencode($files[$i]);
}
I have looked at the header function however I am not if it is what I should be using based upon what I have read.
Thanks for the assistance in advanced.
Rob