php - Downloaded file is empty or fails to find it to begin download -
i'm trying download files site keep encountering problems. firstly downloading empty file, thought because of content type, on suggested application/octet-stream doing. had lot of issues finding file. after few test cases whitespace issue, amend (put in "") , download empty file again.
rudimentary code hoping can help:
<?php $filename = $_get['filename']; $dir = "training/trainingdocuments/"; $downloadfilename = $dir.$filename; //ftp://site.com///training/trainingdocuments/8%20-%20subsea%20questions__51f034ab37a8e.xls //$downloadfilename = preg_replace('/\s/', '%', $downloadfilename); //8 - subsea questions__51f034ab37a8e.xls //if filename exists if(is_file($downloadfilename)){ //send headers header('pragma: public'); //fix ie6 content-disposition header('content-description: file transfer'); header('content-transder-encoding: binary'); header(sprintf('content-length: %u', filesize($downloadfilename))); header('content-type: application/octet-stream'); header("content-disposition: attachment; filename=".$downloadfilename.""); }else{ //file doesn't exist echo "file no exist\n\n"; echo $downloadfilename; }//end if file exists
you never output file, e.g. you're missing
readfile($downloadfilename);
as well, note code allows malicious user download any file on server know path for. consider
$_get['file'] = '../../../../../../../../../etc/passwd';
Comments
Post a Comment