The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Corrupt file download
Discuss Corrupt file download in the PHP Development forum on Dev Shed. Corrupt file download PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 27th, 2013, 12:52 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 19
Time spent in forums: 3 h 1 m 22 sec
Reputation 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?
|

February 27th, 2013, 01:15 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

February 27th, 2013, 01:24 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 19
Time spent in forums: 3 h 1 m 22 sec
Reputation 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.
|

February 27th, 2013, 01:25 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Make the filename the UUID.pdf then, if that works.
|

February 27th, 2013, 01:42 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 19
Time spent in forums: 3 h 1 m 22 sec
Reputation 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.
|

February 27th, 2013, 01:46 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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?
|

February 27th, 2013, 06:00 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 19
Time spent in forums: 3 h 1 m 22 sec
Reputation 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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|