Jump to content


This topic is now archived and is closed to further replies.


Download file - major issue

Recommended Posts

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);
    fclose ($fopen);


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

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.