md5sums of downloaded files are wrong |
md5sums of downloaded files are wrong |
larry78723 |
Mar 8 2022, 10:00 AM
Post
#1
|
Member Group: Members Posts: 39 Joined: 5-March 20 Member No.: 27,220 |
I'm having a problem that files downloaded from my site don't have the same md5sum as the original file. Here's an example:
md5sum of original file: a00bd61088cf4f4a0138d51f24e554f0 md5sum of downloaded file: 6f23af927c0a3348345ed1415fb89e36 I suspect that something is inserting bits into the downloads. I've scrubbed the code for hidden spaces but found none. Here's the code I'm using: CODE <?php function mydloader($filename=NULL) { if( isset( $filename ) ) { $ext = pathinfo($filename, PATHINFO_EXTENSION); { if ($ext == '.iso') header('Content-Type: application/x-cd-image'); elseif ($ext =='.gz') header('Content-Type: application/zip'); else header('Content-Type: octet-stream'); } header('Content-Length: ' .filesize($filename)); header("Content-Disposition: attachment; filename={$filename}"); header('Pragma: no-cache'); header('Expires: 0'); readfile($filename); } else { echo "isset failed"; } } mydloader($_GET["f"]); //passed from calling script I'd appreciate some help on this. |
larry78723 |
Mar 8 2022, 02:13 PM
Post
#2
|
Member Group: Members Posts: 39 Joined: 5-March 20 Member No.: 27,220 |
Won't allow me to edit last post but new info.
Comparison of Sizes: original size: 5674712 download size: 5674783 I also xxd’d both files and compared them in Meld. It appears that the filename is being pre-pended to the downloaded file. |
larry78723 |
Mar 8 2022, 04:58 PM
Post
#3
|
Member Group: Members Posts: 39 Joined: 5-March 20 Member No.: 27,220 |
I'm having a problem that files downloaded from my site don't have the same md5sum as the original file. Here's an example: I've studied the hex code for both the original file and the downloaded file. I found that the file name is being prepended to the downloaded file in the code I posted. I've checked for blank spaces and found none. Does anyone have any ideas about what may be causing this? Thanks in advance. |
Christian J |
Mar 8 2022, 05:04 PM
Post
#4
|
. Group: WDG Moderators Posts: 9,722 Joined: 10-August 06 Member No.: 7 |
No experience with this, but I didn't understand this part:
QUOTE CODE function mydloader($filename=NULL) { Doesn't the above make $filename null? On the other hand, right after comes: QUOTE CODE if( isset( $filename ) ) { which should return false if $filename really was null. BTW, these curly braces look a bit misplaced: QUOTE CODE { if ($ext == '.iso') header('Content-Type: application/x-cd-image'); elseif ($ext =='.gz') header('Content-Type: application/zip'); else header('Content-Type: octet-stream'); } |
larry78723 |
Mar 8 2022, 07:14 PM
Post
#5
|
Member Group: Members Posts: 39 Joined: 5-March 20 Member No.: 27,220 |
BTW, these curly braces look a bit misplaced: QUOTE CODE { if ($ext == '.iso') header('Content-Type: application/x-cd-image'); elseif ($ext =='.gz') header('Content-Type: application/zip'); else header('Content-Type: octet-stream'); } I used the curly braces to offset the if-elseif-else statements from the rest of the headers. It all works, but somehow the filename is being injected into the start of the downloaded file. |
Christian J |
Mar 9 2022, 07:09 AM
Post
#6
|
. Group: WDG Moderators Posts: 9,722 Joined: 10-August 06 Member No.: 7 |
Comparison of Sizes: original size: 5674712 download size: 5674783 QUOTE somehow the filename is being injected into the start of the downloaded file. Maybe it's done by readfile(), or even when the file was first uploaded (say by the FTP program)? This should be possible to test, seems readfile() returns the number of bytes read from the file on success. You could also try running filesize() on various places in the script. |
larry78723 |
Mar 9 2022, 04:26 PM
Post
#7
|
Member Group: Members Posts: 39 Joined: 5-March 20 Member No.: 27,220 |
I've got everything working now. Thanks to all that replied.
|
Christian J |
Mar 9 2022, 04:44 PM
Post
#8
|
. Group: WDG Moderators Posts: 9,722 Joined: 10-August 06 Member No.: 7 |
What was the cause?
|
Lo-Fi Version | Time is now: 26th September 2024 - 03:50 PM |