#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    20
    Rep Power
    0

    Corrupt file download


    Hi,

    I have a situation and I can't figure it out. Any assistance appreciated.

    I have files on my site where the names have been overwritten with a hash string. For example, when uploaded the file may have been "mydoc.pdf" but it is stored as '19a71ff8-810e-11e2-89b8-73e31de31bdf' (a uuid).

    Now, I need to retrieve the file when the user requests it:

    PHP Code:
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past to avoid cached files
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
    //header("Content-Type: application/octet-stream");
    header("Content-Type: " $mimetype);
    header("Content-Disposition: attachment; filename={$filename}");
    header("Content-Transfer-Encoding: binary");
    readfile($fileurl); 
    $filename is "afilename.pdf"
    $mimetype is "application/pdf"
    $fileurl is "/path/to/file/19a71ff8-810e-11e2-89b8-73e31de31bdf"

    The file downloads but the PDF is corrupted; I cannot open it in Adobe. It definitely downloaded a file (it is larger than an error message and I checked the contents with a text editor).

    Any ideas?
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,905
    Rep Power
    6351
    Did it UPLOAD properly? Open it from the server directly.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    20
    Rep Power
    0
    Yes. I took a pdf and renamed it on the server with a UUID name and tried to download it. It came down corrupted. If I add the .PDF extension and open it (the web server is on my development machine), it opens just fine.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,905
    Rep Power
    6351
    Make the filename the UUID.pdf then, if that works.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    20
    Rep Power
    0
    No difference. FIle works when I double click on it through windows, now when I download it.

    Let me be clear. I have the file I will download in a file. It is referenced in a link on the site and I click on it and "download it". The original copy is fine, the downloaded copy is corrupted.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,905
    Rep Power
    6351
    Ok, so:

    On your desktop: Valid.

    Uploaded through your upload form: Valid (downloaded or accessed through a method other than your download form)

    Through your download form: Invalid

    Is that accurate?

    Have you compared the good file to the bad one? Are they the same size? Do they appear the same when you open them in a text editor? Have you tried to change the file extension on the "corrupt" file to .pdf by hand?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    20
    Rep Power
    0
    I figured it out.

    I had two different problems masking as one.

    In the first case, I was trying to download files that were corrupted. When I took one of THOSE, added a .PDF to it the file was corrupted.

    The problem with the other files (the ones I tested and worked), there was an errant " (double quote) in the file name.

    Thanks for your assistance

IMN logo majestic logo threadwatch logo seochat tools logo