Question

Been trying to get this to work for a while now, and I've read through a bunch of SO posts. But I've tried it all, and it doesnt work..

This is the code I'm trying now:

header("Content-type: application/octet-stream");
header("Content-Length: " . filesize($_REQUEST['file']));
header("Content-Disposition: attachment; filename=".basename($_REQUEST['file']));

readfile($_REQUEST['file']);

But it doesnt work. It works for all my other files, but not .FLV. It shows size is 190bytes, and it only saves a file that's 190bytes. It does have the correct url, as I can enter the url in my browser and it plays the video.

Any ideas?

I've tried a lot of headers:

    header('Pragma: public'); // required   
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=".basename($_REQUEST['file']));
    header("Content-Type: video/mpeg");
    header("Content-Transfer-Encoding: binary");

    header("Content-Length: " . filesize($_REQUEST['file']));


    header('Cache-Control: must-revalidate, post-check=0, pre-check=0', false);
    header('Cache-Control: private', false); // required for certain browsers

What I want is a savefile.php file that can save all the different video formats, and also zip, rar, exe and so on files. It would be great if there would be some way of supporting it all, based on the file extension given by the file...

EDIT:


I've even tried using fopen, but nothing works. It shows 190 bytes, but I know for a fact that the url is correct. And the file works (testing this locally on xampp now, so I have easy access to my files)

Was it helpful?

Solution 2

Ahhh, found the answer.. Didnt think about opening up the 190 byte .flv file and check what was in it. There was an error message:

<br />
<b>Fatal error</b>:  Allowed memory size of 134217728 bytes exhausted (tried to allocate  197980160 bytes) in <b>C:\xampp\htdocs\portfolio_003\savefile.php</b> on line <b>47</b><br />

So, I just had to change the value in php.ini

OTHER TIPS

You shouldn't change the memory limit - 32-64 mb is quite enough for almost everything. change your readfile($_REQUEST['file']); into: $handle=fopen($_REQUEST['file'], 'rb'); while (!feof($handle)) { echo fread($handle, 8192); flush(); } fclose($handle); This will read 8kb of file, then push it to the client, and so on... It will consume not much memory (as it's not reading whole file at once).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top