download - php sendfile appends filesize to file -


i have code serve requested files in php. it's testing code, input not validated. (by way, how correctly sanitize kind of input...)

$upload_dir = "/media/usb/dir"; $filename = $_get['filename']; $mimetype = $_get['mime']; $path = $upload_dir . $filename; header('content-description: file transfer'); header("content-type: ".$mimetype ); header('content-disposition: attachment; filename="'.$filename.'"'); header('expires: 0'); header('cache-control: must-revalidate'); header('pragma: public'); header('content-length: ' . filesize($path)); header("x-sendfile: \"$path\""); echo readfile($path); 

but size of file in bytes appended each file. example simple txt this:

myfile 

will become this:

myfile6 

how rid of behaviour?

i'm getting textfile this:

download.php?mime=text/plain&filename=my-file.txt 

readfile() returns size of file. can add @ beginning of function remove error reporting. echo @readfile($path); should display filename.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -