Jump to content


Photo

Download file - major issue


  • Please log in to reply
3 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 01 March 2006 - 03:54 PM

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");

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
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 01 March 2006 - 04:39 PM

What did you expect it to download? The raw PHP code?
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#3 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 01 March 2006 - 04:43 PM

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
http://thewebsolutionprovider.com - A Solution For Everything Web!

#4 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 01 March 2006 - 04:55 PM

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.
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users