CakePHP 1.3媒体视图未正确下载ZIP文件 [英] CakePHP 1.3 Media view not downloading ZIP file correctly

查看:224
本文介绍了CakePHP 1.3媒体视图未正确下载ZIP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的网站从CakePHP 1.1迁移到1.3。



我现在正在使用媒体视图下载文件,但是我有一个主要的问题。 >

当我通过媒体视图下载zip文件,并尝试解压缩它,Windows声称该文件为空。如果我尝试预览它,它说它是无效的。




  • 文件大小正确,与服务器大小相同

  • 我可以下载完全相同文件从服务器通过FTP,这是正确的

  • 我可以通过媒体视图下载一个pdf文件,IT工作正常(但ZIP文件不)



这是我的控制器代码:

  $ this-> view ='Media'; 
$ downloadparams = array(
'id'=>'junkstuff'。'。zip',
'name'=>'junk3',
' > true,
'extension'=>'zip',//必须是小写
'path'=> APP。'tmp / files'。DS //不要忘记终端'DS'
);
$ this-> set($ downloadparams);

再次,如果我更改为pdf文件,并将扩展名更改为pdf,那么都能正常工作。
调试设置为0.

我的代码使用是从1.3蛋糕书直接: http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Views.html



有趣的是,他们使用zip作为蛋糕书中的例子....



我可能做错了什么?



为了参考,这个线程似乎是完全相同的问题,但它也没有答案:
当与winrar打开时,通过Cakephp MediaViews报告获取的Zip文件意外的档案结束

解决方案

事实证明,当我将网站存在于实时服务器上(它在服务器上,但是测试服务器),这个问题自己解决了。唯一可以想到的地方是引用了官方网站名称的引用或安全检查。我的测试网站有不同的网站地址。



这是一个猜测。我真的不知道它固定了什么。但是我没有更改代码,它开始在现场网站上工作。


I recently migrated my site from CakePHP 1.1 to 1.3.

I am now using media view to download files, however, I have a major problem.

When I download a zip file through media view, and try to extract it, windows claims the file is empty. If I try to preview it, it says it is invalid.

  • The file size is correct, same size as on server
  • I can download the exact same file from the server via FTP, and it is correct
  • I can download a pdf file through media view, and IT works correctly (but ZIP files do not)

Here's my controller code:

        $this->view = 'Media';
    $downloadparams = array(
          'id' => 'junkstuff'.'.zip',
          'name' => 'junk3',
          'download' => true,
          'extension' => 'zip',  // must be lower case
          'path' => APP . 'tmp/files' . DS   // don't forget terminal 'DS'
     );
   $this->set($downloadparams);

Again, if I change to a pdf file, and change 'extension' to 'pdf', it all works correctly. Debug is set to 0.
My code usage is straight from the 1.3 Cakebook: http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Views.html

Funny enough, they use zip as an example in the cakebook ....

What might I be doing wrong?

For reference, this thread appears to be the exact same issue, but it has no answers either: when opened with winrar, Zip file obtained through Cakephp MediaViews reports Unexpected end of archive

解决方案

It turns out that when I put the site live on the live server (it was on a server, but my "test" server), this problem fixed itself. The only thing I can think of it that somewhere there was a reference or a security check that referenced the official site name. My test site had a different site address.

That's a guess. I'm really not sure what it fixed itself. But I didn't change the code, and it started working on the live site.

这篇关于CakePHP 1.3媒体视图未正确下载ZIP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆