note 112060 added to function.header

From: Date: Sat, 27 Apr 2013 21:07:24 +0000
Subject: note 112060 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-194645@lists.php.net to get a copy of this message
Just avoid and add some code to work for large file <?php $filename = "theDownloadedFileIsCalledThis.mp3"; $myFile = "/absolute/path/to/my/file.mp3"; // Add bellow code for mime type $ext=strtolower(substr($fl,strrpos($myFile,"."))); $mime_types = array( '.txt' => 'text/plain', '.htm' => 'text/html', '.html' => 'text/html', '.php' => 'text/html', '.css' => 'text/css', '.js' => 'application/javascript', '.json' => 'application/json', '.xml' => 'application/xml', '.swf' => 'application/x-shockwave-flash', '.flv' => 'video/x-flv', // images '.png' => 'image/png', '.jpe' => 'image/jpeg', '.jpeg' => 'image/jpeg', '.jpg' => 'image/jpeg', '.gif' => 'image/gif', '.bmp' => 'image/bmp', '.ico' => 'image/vnd.microsoft.icon', '.tiff' => 'image/tiff', '.tif' => 'image/tiff', '.svg' => 'image/svg+xml', '.svgz' => 'image/svg+xml', // video '.3gp' => 'video/3gpp', '.3g2' => 'video/3g2', '.avi' => 'video/avi', '.mp4' => 'video/mp4', '.asf' => 'video/asf', '.mov' => 'video/quicktime', ); if (array_key_exists($ext, $mime_types)){ $mm_type=$mime_types[$ext]; }else{ $mm_type="application/octet-stream"; } $mm_type="application/octet-stream"; header("Cache-Control: public, must-revalidate"); // Avoid this line header("Pragma: public"); // Add this line header("Pragma: hack"); // Avoid this line header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($myFile)) ); // Avoid this line header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Content-Length: ' . filesize($myFile)); // Add this line header("Content-Transfer-Encoding: binary\n"); ob_clean(); // Add this line readfile($myFile); ?> It should be work fine now. ---- Server IP: 69.147.83.199 Probable Submitter: 115.240.194.128 ---- Manual Page -- http://php.net/manual/en/function.header.php Edit -- https://master.php.net/note/edit/112060 Del: integrated -- https://master.php.net/note/delete/112060/integrated Del: useless -- https://master.php.net/note/delete/112060/useless Del: bad code -- https://master.php.net/note/delete/112060/bad+code Del: spam -- https://master.php.net/note/delete/112060/spam Del: non-english -- https://master.php.net/note/delete/112060/non-english Del: in docs -- https://master.php.net/note/delete/112060/in+docs Del: other reasons-- https://master.php.net/note/delete/112060 Reject -- https://master.php.net/note/reject/112060 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194645) next »