javascript - .zip file downloading as .php -
i have .zip file generated on server using php. file generated valid , checked downloading via ftp etc.
i need create way user download file after generated , file deleted. here headers sending.
header("pragma: public"); header("expires: 0"); header("cache-control: must-revalidate, post-check=0, pre-check=0"); header("cache-control: public"); header("content-description: file transfer"); header('content-type: application/zip'); header("content-transfer-encoding: binary"); header('content-disposition: attachment; filename="'.basename($archive_file_name).'"'); header("content-length: " . filesize($this->dirpath."/".$archive_file_name) ); ob_clean(); //echo is_file($this->dirpath."/".$archive_file_name); readfile($this->dirpath."/".$archive_file_name); unlink($this->dirpath."/".$archive_file_name); exit;
the code above works when try download first few times after few turns starts downloading .php file instead of .zip
the file download triggered going specific link starts creation of zip file. once done, sends out headers begin download
your code looks proper. need ensure preceding , succeeding spaces code.
while adding headers in code, space disrupt , not load zip file.
check once again , remove spaces on top , bottom of page.
and line says
readfile($this->dirpath."/".$archive_file_name);
can removed code
Comments
Post a Comment