<?php
$path = $_GET['file'];
$filename = explode( '/', $path );
$filename = $filename[count( $filename) - 1];
$mimetype = 'application/zip';
header('Content-Description: File Transfer');
header('Content-Type: '.$mimetype);
header('Content-Length: '.filesize($path));
header('Content-Disposition: attachment; filename="'.$filename.'"');
//readfile($path.'/'.$file_name); // This doesnt work as it loads the whole file!!!!
$fp = fopen( $path, 'rb');
while(!feof($fp)) {
print(fread($fp, 1024));
flush();
}
fclose($fp);
?>
[web] PHP and File Streaming Script with Resume Capability
Hello folks.
I was about to bump my old thread here, but it says it has been retired. I guess after a while old topics get automatically locked or something.
Anyway, Ill refer to markr's last reply.
I basically find myself in this situation: I have a download script @ college that saves the downloaded file to the /tmp of the server, since I have a low quota on my shell account there.
The file I downloaded now is a huge (300 Mb+ file) game trailer, but now I need to stream it back home. The point here is not to go to college and get it, etc.. its about having the capacity to create a script that can load the file and stream the content to my web client. In this case, a download manager such as Flashget, or wget.
The problem is that I need download resume support.
According to markr's reply I have to enhance my script with the capacity to handle HTTP 'range' headers... which is something I thought an hour ago, but didnt know the technical term for it.
In any case, I thought the fread() would somehow work fine, and automatically handle a request for a specific offset, but I guess Im blatantly wrong here.
Anyway, this is what Ive been able to pull off so far
Nevermind the mimetype, as I just have it as 'zip' now, but no matter the mimetype, I know the script will work fine for the .mov or any other binary file. And anyway I coded a library for getting mimetypes outta file extensions, so it doesnt matter.
In any case the download is not working at all, dont know what the error might be, but now i know I need to use the range headers as well...
I guess what Im asking for is some pointers on how to get this piece of code to an usable state [embarrass]
Thanks a lot for your time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement