upload - PHP downloading files has been corrupted(While downloading from ftp server) -
i have problem in downloading file(php)from particular folder.
when download , open file says file corrupted.
when check size of uploaded file , downloaded file same , zip file size differs.
no files opening.
can 1 wrong???
if (isset($_get['file']) && basename($_get['file']) == $_get['file']) { $filename = $_get['file']; } else { $filename = null; } $err = 'sorry, file requesting unavailable.'; if (!$filename) { // if variable $filename null or false display message echo $err; } else { // define path download folder plus assign file name $path = '/public_html/wp-content/uploads/'.$filename; // check file exists , readable if (file_exists($path) && is_readable($path)) { // file size , send http headers $size = filesize($path); header ("cache-control: must-revalidate, post-check=0, pre-check=0"); header('content-type: application/octet-stream'); header('content-length: '.$size); header('content-disposition: attachment;filename="'.basename($filename).'"'); header('content-transfer-encoding: binary'); // open file in binary read-only mode // display error messages if file can´t opened $file = @ fopen($path, 'rb'); if ($file) { // stream file , exit script when complete fpassthru($file); exit; } else { echo $err; } } else { echo $err; } exit; }
inserting table:
echo "<tr><td><a href='?file=" . $row["fileupname"]. "'>".$row["fileupname"]."</td></tr>";
i happy file getting downloaded not getting opened.
.txt file getting opened.
had checked header also.
i have tried putting:
ob_clean(); flush(); readfile($file);
if (file_exists($path)) { header('content-description: file transfer'); header('content-type: application/octet-stream'); header('content-disposition: attachment; filename=' . basename($path)); header('content-transfer-encoding: binary'); header('expires: 0'); header('cache-control: must-revalidate, post-check=0, pre-check=0'); header('pragma: public'); header('content-length: ' . filesize($path)); ob_clean(); flush(); readfile($path); exit; }
Comments
Post a Comment