When .zip file downloading, extension comes to .zip.html
Posted: Tue Sep 03, 2013 12:11 am
Hello everyone,
I would like to know how resolve this matter.
When I click zip-file download link,
download will begin,but extension comes to .zip.html.
This is only in safari(6.0.5).
The code is,
Those code fired when I click html link,
[text]
<a href="http://your-domain/?download=XXX">Download this file</a>
[/text]
In Safari ,Donwload file comes to XXX.zip.html.
In Firefox, download file comes to XXX.zip.
Apache/2.2.25
PHP 5.4.17
Why extention .zip change to .zip.html?
Any ideas?
I would like to know how resolve this matter.
When I click zip-file download link,
download will begin,but extension comes to .zip.html.
This is only in safari(6.0.5).
The code is,
Code: Select all
if (isset($_GET['download'])) {
doZipDownload(wp_kses($_GET['download'],array()));
}
function doZipDownload($post_id){
if ( !(( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ){
wp_die( $uploads['error'] );
}
$upload_video_attachment_id = get_post_meta($post_id, 'upload_video_attachment_id',true);
if(!empty($upload_video_attachment_id)){
$file_path = get_attached_file( $upload_video_attachment_id ) ;
$file_name = basename($file_path);
}
$zip_base = $uploads['basedir'];
$zipPath = $zip_base.'/'.$file_name.'.zip';
try {
$zip = new ZipArchive();
$rtn = $zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
if ($rtn !== true) {
wp_die( 'ERROR'.$rtn );
}
$zip->addFile($file_path, $file_name);
$zip->close();
// header('Content-Type: application/zip');
// header('Content-Type: application/octet-stream');
$zipName = mb_convert_encoding($post_id.'.zip', 'UTF-8');
header('Content-Disposition: attachment; filename="' . $zipName.'"');
header('Content-Length: '.filesize($zipPath));
header('Content-Type: application/octet-stream');
readfile($zipPath);
unlink($zipPath);
} catch ( Exception $e ) {
wp_die( $e->getMessage()) ;
}
}
Those code fired when I click html link,
[text]
<a href="http://your-domain/?download=XXX">Download this file</a>
[/text]
In Safari ,Donwload file comes to XXX.zip.html.
In Firefox, download file comes to XXX.zip.
Apache/2.2.25
PHP 5.4.17
Why extention .zip change to .zip.html?
Any ideas?