Re: [PHP] force download
Sebastian wrote: some of my users are complaining that when they try download media files (mp3, mpeg, etc) their media player opens and doesn't allow them to physically download the media. These are IE users, firefox seems to like my code, but IE refuses to download the file and plays it instead.. can anyone view my code and see how i can force media file downloads on IE? We're using the PHP based 'Moodle' system and had the similar problems when downloading stuff in IE. On some IEs it worked, on some IE did nothing, though it was the same version. The only way to fix this, was to search for a 'IE' String, in the browser info and to show another page, with a stupid 'Save as...' link to IE users. hope that works, norbert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
Richard Lynch wrote: Right-click is NOT universal. Macs don't even *have* a right-click! Doesn't Ctrl-Click do the same as a right click? Norbert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
That would be browser dependent, something you have no control over. Maybe you can include a little text message saying right-click save as for the users not intelligent enough to figure it out themselves. - Original Message - From: Sebastian [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, August 10, 2005 12:00 PM Subject: [PHP] force download some of my users are complaining that when they try download media files (mp3, mpeg, etc) their media player opens and doesn't allow them to physically download the media. These are IE users, firefox seems to like my code, but IE refuses to download the file and plays it instead.. can anyone view my code and see how i can force media file downloads on IE? --snip-- header('Cache-control: max-age=31536000'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) . ' GMT'); if ($extension != 'txt') { header(Content-disposition: inline; filename=\$file[type]\); } else { // force txt files to prevent XSS header(Content-disposition: attachment; filename=\$file[type]\); } header('Content-Length: ' . $file['size']); switch($extension) { case 'zip': $headertype = 'application/zip'; break; case 'exe': $headertype = 'application/octet-stream'; break; case 'mp3': $headertype = 'audio/mpeg'; break; case 'wav': $headertype = 'audio/wav'; break; case 'mpg': $headertype = 'video/mpeg'; break; case 'avi': $headertype = 'video/avi'; break; default: $headertype = 'unknown/unknown'; } header('Content-type: ' . $headertype); --/snip-- -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
James R. wrote: That would be browser dependent, something you have no control over. Maybe you can include a little text message saying right-click save as for the users not intelligent enough to figure it out themselves. - Original Message - From: Sebastian [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, August 10, 2005 12:00 PM Subject: [PHP] force download some of my users are complaining that when they try download media files (mp3, mpeg, etc) their media player opens and doesn't allow them to physically download the media. These are IE users, firefox seems to like my code, but IE refuses to download the file and plays it instead.. can anyone view my code and see how i can force media file downloads on IE? --snip-- header('Cache-control: max-age=31536000'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) . ' GMT'); if ($extension != 'txt') { header(Content-disposition: inline; filename=\$file[type]\); } else { // force txt files to prevent XSS header(Content-disposition: attachment; filename=\$file[type]\); } header('Content-Length: ' . $file['size']); switch($extension) { case 'zip': $headertype = 'application/zip'; break; case 'exe': $headertype = 'application/octet-stream'; break; case 'mp3': $headertype = 'audio/mpeg'; break; case 'wav': $headertype = 'audio/wav'; break; case 'mpg': $headertype = 'video/mpeg'; break; case 'avi': $headertype = 'video/avi'; break; default: $headertype = 'unknown/unknown'; } header('Content-type: ' . $headertype); --/snip-- there has to be a way to tell stupid IE Not to open the damn file. i'll be damned to find a way. -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
James R. wrote: That would be browser dependent, something you have no control over. Maybe you can include a little text message saying right-click save as for the users not intelligent enough to figure it out themselves. - Original Message - From: Sebastian [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Wednesday, August 10, 2005 12:00 PM Subject: [PHP] force download some of my users are complaining that when they try download media files (mp3, mpeg, etc) their media player opens and doesn't allow them to physically download the media. These are IE users, firefox seems to like my code, but IE refuses to download the file and plays it instead.. can anyone view my code and see how i can force media file downloads on IE? --snip-- header('Cache-control: max-age=31536000'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) . ' GMT'); if ($extension != 'txt') { header(Content-disposition: inline; filename=\$file[type]\); } else { // force txt files to prevent XSS header(Content-disposition: attachment; filename=\$file[type]\); } header('Content-Length: ' . $file['size']); switch($extension) { case 'zip': $headertype = 'application/zip'; break; case 'exe': $headertype = 'application/octet-stream'; break; case 'mp3': $headertype = 'audio/mpeg'; break; case 'wav': $headertype = 'audio/wav'; break; case 'mpg': $headertype = 'video/mpeg'; break; case 'avi': $headertype = 'video/avi'; break; default: $headertype = 'unknown/unknown'; } header('Content-type: ' . $headertype); --/snip-- forgot to mention, they can't right click to save as because if you notice from my code i am pushing the file to them... without an actual path to the file. so if they did do a save as it'll just save the php/html output, which will be blank in this case. -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
A comment is inline. Sebastian wrote: some of my users are complaining that when they try download media files (mp3, mpeg, etc) their media player opens and doesn't allow them to physically download the media. These are IE users, firefox seems to like my code, but IE refuses to download the file and plays it instead.. can anyone view my code and see how i can force media file downloads on IE? --snip-- header('Cache-control: max-age=31536000'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) . ' GMT'); if ($extension != 'txt') { header(Content-disposition: inline; filename=\$file[type]\); } else { // force txt files to prevent XSS header(Content-disposition: attachment; filename=\$file[type]\); } if you just remove this extension check, and set everything as an attachment, that is the normal way to do things. The major browsers will pop up a Save As... dialog header('Content-Length: ' . $file['size']); switch($extension) { case 'zip': $headertype = 'application/zip'; break; case 'exe': $headertype = 'application/octet-stream'; break; case 'mp3': $headertype = 'audio/mpeg'; break; case 'wav': $headertype = 'audio/wav'; break; case 'mpg': $headertype = 'video/mpeg'; break; case 'avi': $headertype = 'video/avi'; break; default: $headertype = 'unknown/unknown'; } header('Content-type: ' . $headertype); --/snip-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
On Wed, August 10, 2005 12:49 pm, Chris wrote: if ($extension != 'txt') { header(Content-disposition: inline; filename=\$file[type]\); } else { // force txt files to prevent XSS header(Content-disposition: attachment; filename=\$file[type]\); } The Content-disposition header is a made-up bull-crap thing that came about with html enhanced (cough, cough) email. If you want *EVERY* browser to download something, forget this header and use: header(Content-type: application/octet-stream); The Content-disposition will, on *SOME* browsers, on *SOME* OSes appear to be useful for getting the filename in the dialog prompt for Save As... to be the filename you want. Unfortunately, it does *NOT* work universally. If you want a UNIVERSAL solution, make the URL look like it's a static URL and have the filename you want to be used appear at the end of the URL. Converting dynamic to static-looking URLs is covered in many places. Google for PHP $_SERVER PATHINFO Under no circumstances should you be using headers like audio/mpeg if you want me to download it -- I guarantee my browser will open that up in an MP3 player. Many other users will also have been led through the process to make that happen. But if the browser doesn't download application/octet-stream it's a very very very broken browser. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
On Wed, August 10, 2005 12:43 pm, Sebastian wrote: That would be browser dependent, something you have no control over. Maybe you can include a little text message saying right-click save as for the users not intelligent enough to figure it out themselves. I defy you to find any web browser that doesn't download a file whose Content-type: header is application/octet-stream Right-click is NOT universal. Macs don't even *have* a right-click! -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
Richard Lynch wrote: On Wed, August 10, 2005 12:49 pm, Chris wrote: if ($extension != 'txt') { header(Content-disposition: inline; filename=\$file[type]\); } else { // force txt files to prevent XSS header(Content-disposition: attachment; filename=\$file[type]\); } The Content-disposition header is a made-up bull-crap thing that came about with html enhanced (cough, cough) email. If you want *EVERY* browser to download something, forget this header and use: header(Content-type: application/octet-stream); The Content-disposition will, on *SOME* browsers, on *SOME* OSes appear to be useful for getting the filename in the dialog prompt for Save As... to be the filename you want. Unfortunately, it does *NOT* work universally. If you want a UNIVERSAL solution, make the URL look like it's a static URL and have the filename you want to be used appear at the end of the URL. Converting dynamic to static-looking URLs is covered in many places. Google for PHP $_SERVER PATHINFO Under no circumstances should you be using headers like audio/mpeg if you want me to download it -- I guarantee my browser will open that up in an MP3 player. Many other users will also have been led through the process to make that happen. But if the browser doesn't download application/octet-stream it's a very very very broken browser. if i don't use Content-disposition IE downloads the file as unknown (mp3, exe, or otherwise) with no extension and the names the file you are downloading becomes the name of the script that was called. lol? can never win with IE .. -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download
On Wed, August 10, 2005 2:07 pm, Sebastian wrote: if i don't use Content-disposition IE downloads the file as unknown (mp3, exe, or otherwise) with no extension and the names the file you are downloading becomes the name of the script that was called. lol? So here's what you do. Go ahead and RENAME your PHP script to next_hit_song.mp3 Then use .htaccess to tell Apache that it's *REALLY* a PHP script even though it ends in .mp3 Files next_hit_song.mp3 application/x-httpd-php /Files That is what I mean by making the URL look static IE is so [bleeping] stupid about URLs and content-type and rich media, that you simply cannot give it any room for a mistake. Consider the MP3s and m3u s on the pages here: http://uncommonground.com/ http://uncommonground.com/artist_profile/Ellen+Rosner Every one of the MP3/m3u files you can find there is really a PHP script. They just happen to end in .mp3 and .m3u so IE can't [bleep] up. The dynamic MP3 downloads (and streams) have the MP3 ID3 tags inserted at download time, so the artists can correct typos or give me info like song title and whatnot lonnng after the actual mp3 is created, identified, and cataloged. The m3u playlists are coming out the database from queries with all kinds of interesting properties. New playlist every day on the homepage. Different playlist every download on the calendar pages: http://uncommonground.com/events.htm While you are there, check out that PDF. Yup. That ain't really a PDF, it's a PHP script. But even IE can't manage to screw up when the URL is http://uncommonground.com/events.pdf I do need to fix the ones where the date (past/future months) is passed as a GET argument. Some versions of IE on the Mac mess that up. Sigh. In my spare time. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download with header()
Are you using Internet Explorer? Then it's a feature of IE--it ignores the disposition headers sent by your server because its registry tells it that PDF files must be viewed inline. There's a way around it, although it's a bit kludgy--I wrote a small article about it that you can find here (it's in PDF format, as well): http://www.phparch.com/issuedata/2002/december/sample.php Essentially, you're telling IE to download a file with the extension .pdf (not the space) so that it can't match the MIME type anymore and will follow your suggestion of downloading the file instead of displaying it inline. Hope this helps! Cheers, Marco -- php|architect - The Magazine for PHP Professionals The monthly magazine dedicated to the world of PHP programming Check us out on the web at http://www.phparch.com! ---BeginMessage--- i was reading about php.net looking for a way to force a download of a txt file, rather than the browser displaying the file. i ran into header() that seems to be able to accomplish it... but seeing as i'm very much a newbie at php, i can't seem to make this work if the file i want to download is nfo/60/ind.txt how would i impliment this: ?php // We'll be outputting a PDF header(Content-type: application/pdf); // It will be called downloaded.pdf header(Content-Disposition: attachment; filename=downloaded.pdf); // The PDF source is in original.pdf readfile('original.pdf'); ? ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download and file size issue
this is what i have exactly in my code... header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); readfile($file_fullpath); exit; it works for files upto 10M (same as memory limit) but not above. the paths to file and content length are correct as i have checked them and made comparisons to other files which i can download. is there a problem with this code? i have tried it with win ie 6 and mac ie 5.1.2 and ns 4.7.. same issue cheers christian Rasmus Lerdorf wrote: readfile() reads 8k blocks at a time and dumps them out. It does not read the entire thing into ram, so that wouldn't be what was causing you to hit a memory limit. You must have done something else wrong then. -Rasmus On Fri, 4 Oct 2002, christian haines wrote: thanks rasmus, i have tried read file but it gave me the same issues as fpassthru.. both cap on the memory_limit directive withint the php.ini file any other suggestions maybe? cheers christian Rasmus Lerdorf wrote: readfile() On Fri, 4 Oct 2002, christian haines wrote: hi all, i have successfully created a download script to force a user to download, however attempting to download large files causes an error saying that the file cannot be found. my code header(Cache-control: private); header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); $fp = fopen($file_fullpath,r); fpassthru($fp); fclose($fp); my code this is a memory issue in the php.ini i.e. memory_limit = 8M then the largest file i can download is 8M is there anyway to force a download without having to use the system hungry fpassthru function? this is driving me nuts so any help would be greatly appreciated cheers christian ps i read the following at php.net fpassthru man page but could not make sense of it (it appears to be some kind of solution) fpassthru() works best for small files. In download manager scripts, it's best to determine the URL of the file to download (you may generate it locally in your session data if you need so), and then use HTTP __temporary__ redirects (302 status code, with a Location: header specifying the effective download URL). This saves your web server from maintaining PHP scripts running for long times during the file downloadn and instead the download will be managed directly by the web server without scripting support (consequence: less memory resources used by parallel downloads)... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download and file size issue
Which OS and which PHP version? On Fri, 4 Oct 2002, christian haines wrote: this is what i have exactly in my code... header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); readfile($file_fullpath); exit; it works for files upto 10M (same as memory limit) but not above. the paths to file and content length are correct as i have checked them and made comparisons to other files which i can download. is there a problem with this code? i have tried it with win ie 6 and mac ie 5.1.2 and ns 4.7.. same issue cheers christian Rasmus Lerdorf wrote: readfile() reads 8k blocks at a time and dumps them out. It does not read the entire thing into ram, so that wouldn't be what was causing you to hit a memory limit. You must have done something else wrong then. -Rasmus On Fri, 4 Oct 2002, christian haines wrote: thanks rasmus, i have tried read file but it gave me the same issues as fpassthru.. both cap on the memory_limit directive withint the php.ini file any other suggestions maybe? cheers christian Rasmus Lerdorf wrote: readfile() On Fri, 4 Oct 2002, christian haines wrote: hi all, i have successfully created a download script to force a user to download, however attempting to download large files causes an error saying that the file cannot be found. my code header(Cache-control: private); header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); $fp = fopen($file_fullpath,r); fpassthru($fp); fclose($fp); my code this is a memory issue in the php.ini i.e. memory_limit = 8M then the largest file i can download is 8M is there anyway to force a download without having to use the system hungry fpassthru function? this is driving me nuts so any help would be greatly appreciated cheers christian ps i read the following at php.net fpassthru man page but could not make sense of it (it appears to be some kind of solution) fpassthru() works best for small files. In download manager scripts, it's best to determine the URL of the file to download (you may generate it locally in your session data if you need so), and then use HTTP __temporary__ redirects (302 status code, with a Location: header specifying the effective download URL). This saves your web server from maintaining PHP scripts running for long times during the file downloadn and instead the download will be managed directly by the web server without scripting support (consequence: less memory resources used by parallel downloads)... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download and file size issue
PHP Version 4.1.2 Red Hat Linux release 7.3 (Valhalla) (Kernel 2.4.18-3 on an i686) Apache/1.3.23 Rasmus Lerdorf wrote: Which OS and which PHP version? On Fri, 4 Oct 2002, christian haines wrote: this is what i have exactly in my code... header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); readfile($file_fullpath); exit; it works for files upto 10M (same as memory limit) but not above. the paths to file and content length are correct as i have checked them and made comparisons to other files which i can download. is there a problem with this code? i have tried it with win ie 6 and mac ie 5.1.2 and ns 4.7.. same issue cheers christian Rasmus Lerdorf wrote: readfile() reads 8k blocks at a time and dumps them out. It does not read the entire thing into ram, so that wouldn't be what was causing you to hit a memory limit. You must have done something else wrong then. -Rasmus On Fri, 4 Oct 2002, christian haines wrote: thanks rasmus, i have tried read file but it gave me the same issues as fpassthru.. both cap on the memory_limit directive withint the php.ini file any other suggestions maybe? cheers christian Rasmus Lerdorf wrote: readfile() On Fri, 4 Oct 2002, christian haines wrote: hi all, i have successfully created a download script to force a user to download, however attempting to download large files causes an error saying that the file cannot be found. my code header(Cache-control: private); header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); $fp = fopen($file_fullpath,r); fpassthru($fp); fclose($fp); my code this is a memory issue in the php.ini i.e. memory_limit = 8M then the largest file i can download is 8M is there anyway to force a download without having to use the system hungry fpassthru function? this is driving me nuts so any help would be greatly appreciated cheers christian ps i read the following at php.net fpassthru man page but could not make sense of it (it appears to be some kind of solution) fpassthru() works best for small files. In download manager scripts, it's best to determine the URL of the file to download (you may generate it locally in your session data if you need so), and then use HTTP __temporary__ redirects (302 status code, with a Location: header specifying the effective download URL). This saves your web server from maintaining PHP scripts running for long times during the file downloadn and instead the download will be managed directly by the web server without scripting support (consequence: less memory resources used by parallel downloads)... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download and file size issue
thanks for all your help and that last suggestion. it helped me isolate the issue. which i believe relates to a header previously sent.still debugging it but got a simple vers running cheers christian Rasmus Lerdorf wrote: Which OS and which PHP version? On Fri, 4 Oct 2002, christian haines wrote: this is what i have exactly in my code... header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); readfile($file_fullpath); exit; it works for files upto 10M (same as memory limit) but not above. the paths to file and content length are correct as i have checked them and made comparisons to other files which i can download. is there a problem with this code? i have tried it with win ie 6 and mac ie 5.1.2 and ns 4.7.. same issue cheers christian Rasmus Lerdorf wrote: readfile() reads 8k blocks at a time and dumps them out. It does not read the entire thing into ram, so that wouldn't be what was causing you to hit a memory limit. You must have done something else wrong then. -Rasmus On Fri, 4 Oct 2002, christian haines wrote: thanks rasmus, i have tried read file but it gave me the same issues as fpassthru.. both cap on the memory_limit directive withint the php.ini file any other suggestions maybe? cheers christian Rasmus Lerdorf wrote: readfile() On Fri, 4 Oct 2002, christian haines wrote: hi all, i have successfully created a download script to force a user to download, however attempting to download large files causes an error saying that the file cannot be found. my code header(Cache-control: private); header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); $fp = fopen($file_fullpath,r); fpassthru($fp); fclose($fp); my code this is a memory issue in the php.ini i.e. memory_limit = 8M then the largest file i can download is 8M is there anyway to force a download without having to use the system hungry fpassthru function? this is driving me nuts so any help would be greatly appreciated cheers christian ps i read the following at php.net fpassthru man page but could not make sense of it (it appears to be some kind of solution) fpassthru() works best for small files. In download manager scripts, it's best to determine the URL of the file to download (you may generate it locally in your session data if you need so), and then use HTTP __temporary__ redirects (302 status code, with a Location: header specifying the effective download URL). This saves your web server from maintaining PHP scripts running for long times during the file downloadn and instead the download will be managed directly by the web server without scripting support (consequence: less memory resources used by parallel downloads)... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download and file size issue
readfile() On Fri, 4 Oct 2002, christian haines wrote: hi all, i have successfully created a download script to force a user to download, however attempting to download large files causes an error saying that the file cannot be found. my code header(Cache-control: private); header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); $fp = fopen($file_fullpath,r); fpassthru($fp); fclose($fp); my code this is a memory issue in the php.ini i.e. memory_limit = 8M then the largest file i can download is 8M is there anyway to force a download without having to use the system hungry fpassthru function? this is driving me nuts so any help would be greatly appreciated cheers christian ps i read the following at php.net fpassthru man page but could not make sense of it (it appears to be some kind of solution) fpassthru() works best for small files. In download manager scripts, it's best to determine the URL of the file to download (you may generate it locally in your session data if you need so), and then use HTTP __temporary__ redirects (302 status code, with a Location: header specifying the effective download URL). This saves your web server from maintaining PHP scripts running for long times during the file downloadn and instead the download will be managed directly by the web server without scripting support (consequence: less memory resources used by parallel downloads)... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download and file size issue
thanks rasmus, i have tried read file but it gave me the same issues as fpassthru.. both cap on the memory_limit directive withint the php.ini file any other suggestions maybe? cheers christian Rasmus Lerdorf wrote: readfile() On Fri, 4 Oct 2002, christian haines wrote: hi all, i have successfully created a download script to force a user to download, however attempting to download large files causes an error saying that the file cannot be found. my code header(Cache-control: private); header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); $fp = fopen($file_fullpath,r); fpassthru($fp); fclose($fp); my code this is a memory issue in the php.ini i.e. memory_limit = 8M then the largest file i can download is 8M is there anyway to force a download without having to use the system hungry fpassthru function? this is driving me nuts so any help would be greatly appreciated cheers christian ps i read the following at php.net fpassthru man page but could not make sense of it (it appears to be some kind of solution) fpassthru() works best for small files. In download manager scripts, it's best to determine the URL of the file to download (you may generate it locally in your session data if you need so), and then use HTTP __temporary__ redirects (302 status code, with a Location: header specifying the effective download URL). This saves your web server from maintaining PHP scripts running for long times during the file downloadn and instead the download will be managed directly by the web server without scripting support (consequence: less memory resources used by parallel downloads)... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] force download and file size issue
readfile() reads 8k blocks at a time and dumps them out. It does not read the entire thing into ram, so that wouldn't be what was causing you to hit a memory limit. You must have done something else wrong then. -Rasmus On Fri, 4 Oct 2002, christian haines wrote: thanks rasmus, i have tried read file but it gave me the same issues as fpassthru.. both cap on the memory_limit directive withint the php.ini file any other suggestions maybe? cheers christian Rasmus Lerdorf wrote: readfile() On Fri, 4 Oct 2002, christian haines wrote: hi all, i have successfully created a download script to force a user to download, however attempting to download large files causes an error saying that the file cannot be found. my code header(Cache-control: private); header(Content-Type: application/force-download; name=\$file\); header(Content-Disposition: attachment; filename=\$file \); header(Content-Transfer-Encoding: binary); header(Content-Length: $content_length); $fp = fopen($file_fullpath,r); fpassthru($fp); fclose($fp); my code this is a memory issue in the php.ini i.e. memory_limit = 8M then the largest file i can download is 8M is there anyway to force a download without having to use the system hungry fpassthru function? this is driving me nuts so any help would be greatly appreciated cheers christian ps i read the following at php.net fpassthru man page but could not make sense of it (it appears to be some kind of solution) fpassthru() works best for small files. In download manager scripts, it's best to determine the URL of the file to download (you may generate it locally in your session data if you need so), and then use HTTP __temporary__ redirects (302 status code, with a Location: header specifying the effective download URL). This saves your web server from maintaining PHP scripts running for long times during the file downloadn and instead the download will be managed directly by the web server without scripting support (consequence: less memory resources used by parallel downloads)... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php