yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.92k forks source link

download file does not work in Safari correctly #13001

Closed jbmckee closed 7 years ago

jbmckee commented 7 years ago

I am using the following to allow a user to download a generated zip file:

    $headers = Yii::$app->response->headers;
    $headers->set('Content-Disposition', "attachment; filename={$file_name}");
    $headers->set('Content-Type', 'application/zip');
    Yii::$app->response->content = $zipfile;
    return;

This works fine in every browser except Safari. Unfortunately, if the file name is file.zip, it downloads as file.zip.html

However, this works as expected: header('Content-Type: application/zip'); header("Content-disposition: attachment; filename={$file_name}"); echo $zipfile; exit;

Q A
Yii version 2.0.?
PHP version
Operating system
samdark commented 7 years ago

Have you tried special response methods for file uploads?

yii-bot commented 7 years ago

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

jbmckee commented 7 years ago

I originally was going to use Yii::$app->response->sendContentAsFile($zipfile, $file_name)->send(); but was under the impression that there was a bug with this method. This is why I went with the Yii::$app->response->content = $zipfile;

However, I just tried Yii::$app->response->sendContentAsFile($zipfile, $file_name)->send(); on Mac in both Chrome and Safari and by golly, it did work. So, maybe whatever bug there was has been fixed.

Thanks for your attention.