glenelkins Posted March 1, 2006 Share Posted March 1, 2006 [code]function downloadFile($thefile) { header ("Pragma: public"); header ("Expires: 0"); header ("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header ("Cache-Control: public"); header ("Content-Description: File Transfer"); header ("Content-Length: ".filesize($thefile)); header ("Content-Disposition: attachment; filename=".$thefile); header ("Content-Transfer-Encoding: binary"); $fopen = fopen($thefile); fpassthru($fopen); fclose ($fopen);}downloadFile("filename");[/code]Ok when this code is run it is supposed to download the file. It does exactly that. but, this code is on a page called users.php, all it does is download the internet explorer source for this pages code. Why is it doing this Quote Link to comment https://forums.phpfreaks.com/topic/3837-download-file-major-issue/ Share on other sites More sharing options...
XenoPhage Posted March 1, 2006 Share Posted March 1, 2006 What did you expect it to download? The raw PHP code? Quote Link to comment https://forums.phpfreaks.com/topic/3837-download-file-major-issue/#findComment-13329 Share on other sites More sharing options...
glenelkins Posted March 1, 2006 Author Share Posted March 1, 2006 Well its a file manager. I want the user to click the download button next to any file and download the file. I tested this with a zip file also, it downloaded the file but would not open it. I then tried a php file and it downloaded it but not the actual code file but the source from IE. Dont know why its doing this. any file i download it wont open it or it opens as a load of crap Quote Link to comment https://forums.phpfreaks.com/topic/3837-download-file-major-issue/#findComment-13332 Share on other sites More sharing options...
XenoPhage Posted March 1, 2006 Share Posted March 1, 2006 Well, I'm not an fopen expert, but I believe you have 2 problems here. First, .zip is a binary format and you're streaming ascii data to the file. You need to use fopen($filename, 'rb') to open a binary file.For the .php file problem, when it "downloads", I'm not sure.. I tried it here and I get the raw code, as expected..Also, as a side note, I get an error if I call fopen with only one argument. The string mode argument is required. Quote Link to comment https://forums.phpfreaks.com/topic/3837-download-file-major-issue/#findComment-13333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.