flyhoney Posted May 2, 2007 Share Posted May 2, 2007 I want a user to be able to download a .zip file from my server, without actually hardlinking to the file. Ive seen this done, I just dont know how to do it. I want a user to be given a link to something like: download.php?file=345342343 and have that script send the file to them. Ive tried something to the effect of: header("Content-type: application/zip"); $f = fopen(yada yada); while( $f != eof ){ echo yadayada; } But that didn't seem to work, any ideas? Link to comment https://forums.phpfreaks.com/topic/49595-sending-files-to-browser/ Share on other sites More sharing options...
jitesh Posted May 2, 2007 Share Posted May 2, 2007 <?php $filename=$_REQUEST['filename']; $filename = realpath($filename); $file_extension = strtolower(substr(strrchr($filename,"."),1)); /****Set Header Content Type based on File Extension****/ switch ($file_extension) { case "zip": $ctype="zip"; break; default: $ctype="application/force-download"; } if (!file_exists($filename)) { die("NO FILE HERE"); } header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: $ctype"); header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename=\"".basename($filename)."\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); set_time_limit(0); @readfile("$filename") or die("File not found."); ?> Link to comment https://forums.phpfreaks.com/topic/49595-sending-files-to-browser/#findComment-243182 Share on other sites More sharing options...
flyhoney Posted May 2, 2007 Author Share Posted May 2, 2007 thnx, ilu, problem solved. Link to comment https://forums.phpfreaks.com/topic/49595-sending-files-to-browser/#findComment-243183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.