The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
A question about file php header
Discuss A question about file php header in the PHP Development forum on Dev Shed. A question about file php header PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 2nd, 2012, 01:20 AM
|
 |
A Change of Season
|
|
|
|
|
A question about file php header
The file is about 300mb, it downloads a 1kb file!
The file format is a .m4v video. What am I doing wrong?
(It works for .mov files but my files have to be m4v)!
Thanks.
PHP Code:
header('Content-Description: File Transfer');
header('Content-Type: video/m4v');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
Last edited by zxcvbnm : September 2nd, 2012 at 02:42 AM.
|

September 2nd, 2012, 04:26 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
What's the contents of the file? The 1KB one you downloaded, not what you're trying to get.
|

September 2nd, 2012, 08:32 AM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by requinix What's the contents of the file? The 1KB one you downloaded, not what you're trying to get. | Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 303388673 bytes) in /hsphere/local/home/behnam/****.com/controllers/download.php on line 29
|

September 2nd, 2012, 08:31 PM
|
 |
A Change of Season
|
|
|
|
This is working. The only problem is when I am downloading, I cannot access the same wesbites from the same browser window!
Is this an issue I could fix? Maybe I compress the file to zip and then allow them to download a zip?
Thank you
PHP Code:
ini_set("memory_limit","900M");
$file="/hsphere/local/home/behnam/download_stuff/video.m4v";
header('Content-Description: File Transfer');
header('Content-Type: video/x-m4v');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Length: ' . filesize($file));
readfile($file);
Last edited by zxcvbnm : September 2nd, 2012 at 09:24 PM.
|

September 3rd, 2012, 02:05 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Don't up the memory limit to something as ridiculous as 900M. Keep it low, at like 128MB or so, and if you run into problems then fix the problems.
Apparently readfile() buffers the file into memory. Try a simple fopen/fread/fclose loop instead.
|

September 3rd, 2012, 02:48 AM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by requinix Don't up the memory limit to something as ridiculous as 900M. Keep it low, at like 128MB or so, and if you run into problems then fix the problems.
Apparently readfile() buffers the file into memory. Try a simple fopen/fread/fclose loop instead. | The file is 890mb.
|

September 3rd, 2012, 02:53 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
And?
|

September 3rd, 2012, 04:24 AM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by requinix And? | Miss, I tried this script but I get error again! Please guide. Thanks
PHP Code:
$file="/hsphere/local/home/video_medium.m4v";
header('Content-Description: File Transfer');
header('Content-Type: video/x-m4v');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Length: ' . filesize($file));
$handle = fopen($file,'r');
echo $content = fread($handle, filesize($file));
fclose($handle);
Quote: | Fatal error: Allowed memory size of 734003200 bytes exhausted (tried to allocate 529375233 bytes) in ******* on line 38 //Line 38 echo $content = fread($handle, filesize($file)); | Edit:
Same with: echo file_get_contents($file);
Last edited by zxcvbnm : September 3rd, 2012 at 04:28 AM.
|

September 3rd, 2012, 04:49 AM
|
 |
A Change of Season
|
|
|
|
Thanks. Looks like this is working fine:
PHP Code:
set_time_limit(0);
$filer = @fopen($file,"rb");
while(!feof($filer))
{
print(@fread($filer, 1024*8));
ob_flush();
flush();
}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|