I use forced download to upload mainly zips and mp3 to the site I made ( http://pr1pad.kissyour.net ) - track downloads in Google analytics, in the database and hide the real download path:
It:
extending CI model ... - bunch of code function _fullread ($sd, $len) { $ret = ''; $read = 0; while ($read < $len && ($buf = fread($sd, $len - $read))) { $read += strlen($buf); $ret .= $buf; } return $ret; } function download(){ /* DOWNLOAD ITSELF */ ini_set('memory_limit', '160M'); apache_setenv('no-gzip', '1'); ob_end_flush(); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public",FALSE); header("Content-Description: File Transfer"); header("Content-type: application/octet-stream"); if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) header('Content-Type: application/force-download'); //IE HEADER header("Accept-Ranges: bytes"); header("Content-Disposition: attachment; filename=\"" . basename("dir-with- files/".$filename) . "\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize("dir-with-files/".$filename)); // Send file for download if ($stream = fopen("dir-with-files/$filename", 'rb')){ while(!feof($stream) && connection_status() == 0){ //reset time limit for big files set_time_limit(0); print($this->_fullread($stream,1024*16)); flush(); } fclose($stream); } }
This is on LAMP with CI 1.7.2. This is my own method, made up of different practices throughout the Internet, because during development these problems arose: - server limitation . ini_set did not help, so I used buffered _fullread instead of the usual fread , which was used insted from @readonly - ob_end_flush (), because the site is executed in CI1.7.2, and I need to clear the buffer
Now ... This will not work. So it was, then it stopped showing the expected size / loading time - I tried to clear it, and while I was clearing the code, something happened, I do not know that in any previous version it did not work (no changes in the settings in general) - edit: do not work = displays everything in a browser window.
So, I said, screw it in, I'll look here.
So, I'm basically looking for a script or function that I can put in my output model and do:
- Force download call (at the beginning of Chrome download, in IE, FF, Safari open modal opening / saving / canceling)
- Show file size and estimated dl time (what about the browser, I know, but first the browser should know the file size
- WORK (verified and verified!) In IE6,7,8, FF3, Opera, Chrome and Safari on PC + Mac (Linux ... I don't care) - this is for part of the header
- on the server, I also have something like a 56 MB memory limit, which I cannot add to, so itโs also important
Thanks in advance.
Edit : now I feel more screwed up than ever / before, since I tried to force download using .htaccess - while it worked, it had a few minor / major (pick yours) problems
- he showed the full path (insignificant for me)
- it waits for the complete download to complete (shown as a โconnectionโ), and then just shows its download - and download in one second (major for me).
Now, although I deleted .htaccess, it is still waiting for the download to complete (as if it first loaded into the cache), and it just gets connected and opens the open / save dialog.