moon_php Posted April 24, 2010 Share Posted April 24, 2010 Not 100% sure that my problem is PHP related but here goes: Background: I have a php download script (see below) that hides the real location of the files and creates a download log. Some of the download-able files are mirrored on remote servers. Problem: When downloading one of the mirrored files, the dialog ('open'/'save as') still says that it is downloaded from my site e.g. "from: http://www.mysite.com"! Question: Is there a way to change my script to display the real host of the mirrored file? <?php require ("dl_filenames.php"); //Get array of all valid filenames define('LOG_DOWNLOADS',true); // log downloads? true/false define('LOG_FILE','dl_logfile.log'); // log file name $fname = basename(@$_GET['f']); // get filename if (in_array($fname, $filename,true)) { $path = "http://somesite.com/files/"; // path to files $fullPath = $path.$fname; $remoteFile = $fullPath; $ch = curl_init($remoteFile); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $data = curl_exec($ch); curl_close($ch); if ($data === false) { echo 'cURL failed'; exit; } $contentLength = 'unknown'; $status = 'unknown'; if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) { $status = (int)$matches[1]; } if (preg_match('/Content-Length: (\d+)/', $data, $matches)) { $contentLength = (int)$matches[1]; } if ($fd = @fopen ($fullPath, "rb")) { // $fsize = filesize($fullPath); $fhost = parse_url($path, PHP_URL_HOST); $path_parts = pathinfo($fullPath); // $filehost = $path_parts["dirname"]; $ext = strtolower($path_parts["extension"]); switch ($ext) { case "zip"; header("Content-type: application/zip"); header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); break; case "rar": header("Content-type: application/x-rar-compressed"); header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); break; case "7z": header("Content-type: application/x-7z-compressed"); header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); break; default; header("Content-type: application/octet-stream"); header("Content-Disposition: filename=\"".$path_parts["basename"]."\""); } header("Content-length: $contentLength"); header("Content-Location: $fhost"); // header("Cache-control: private"); //use this to open files directly while(!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } @fclose ($fd); // log downloads if (!LOG_DOWNLOADS) die(); $f = @fopen(LOG_FILE, 'a+'); if ($f) { @fputs($f, date("d.m.Y g:ia").",".$_SERVER['REMOTE_ADDR'].",".$fname.",".$path."\n"); @fclose($f); } } exit; ?> Link to comment https://forums.phpfreaks.com/topic/199619-download-script-problem/ Share on other sites More sharing options...
mattal999 Posted April 24, 2010 Share Posted April 24, 2010 I don't think so, but if the file is a .zip or .exe, then you could just send them to the actual file using a header("Location:file.zip"); command. Other than that, I don't think it's possible. Link to comment https://forums.phpfreaks.com/topic/199619-download-script-problem/#findComment-1047776 Share on other sites More sharing options...
moon_php Posted April 25, 2010 Author Share Posted April 25, 2010 Thanks for your reply mattal999. As it's probably only me that is going to notice this, I guess I can live with it Link to comment https://forums.phpfreaks.com/topic/199619-download-script-problem/#findComment-1047916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.