Jump to content

File Download


jaymc

Recommended Posts

Im using headers to output a file as a SAVE AS link rather than to open it up in its default application when you click the direct link

It works fine, but, I think its downloading them in ascii or something becayse when downloading an image it becomes corrupt. Its the same with a few other files that generally require binary download

Below is the code

[code]    header("Pragma: public");
    header("Expires: 0"); // set expiration time
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Disposition: attachment; filename=Jaydiocity_$filename[1]");
    header("Content-Transfer-Encoding: binary");


readfile("./uploads/".$file);[/code]

Once again, the file downloads fine in full but is somehow corrupt. E.G a jpg file does not open up in the likes of windows FAX viewer, but will open up in paint shop pro for instance which obviously has some kind of error correction built in

Any ideas?
Link to comment
Share on other sites

When using complex variables (such as arrays) inside strings you need to enclose them in curly brackets ( {} ). Another header you might want to send is the Content-length header so the browser will know the size and thereby can estimate the time left to download the file.

Where does $file come from?

Edit: I really have to read the entire topic before replying. I think the thing I mentioned about the curly brackets could break it as if it has a wrong file extensions it's associations would be incorrect.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.