Codeigniter下载助手会损坏.7z和.rar文件帮助或替代解决方案? [英] Codeigniter Download Helper corrupts .7z and .rar files help or alternative solutions?

查看:95
本文介绍了Codeigniter下载助手会损坏.7z和.rar文件帮助或替代解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeigniter的下载帮助程序进行轻松下载。

  $ this-> load-> helper( '下载'); 
$ file = // get_file_name_from_db
$ data = file_get_contents(upload_path。$ file);
force_download($ file,$ data);

我遇到的问题是,任何.zip都可以正确下载,而.7z和.rar却没有。但是,当我检查上传的文件以查看它们是否损坏时(通过FTP或通过简单地检查文件夹在本地)就可以了。



要添加到如果文件很小(例如5kb左右),则会造成混乱,那么所有类型(7z和rar)都不会损坏。



此处提供的是mime类型供参考我在mime.php中使用(上传和下载助手都使用)

 'zip'=>数组(应用程序/ x-zip,应用程序/ zip,应用程序/ x-zip压缩),
7z => array('application / x-7z-compressed','application / x-7z','application / 7z','application / force-download','application / octet-stream'),
'rar' => array('application / x-rar-compressed','application / x-rar','application / rar','application / octet-stream')

问题可能出在两点,两种都是哑剧类型(因为如前所述,这在很小的文件大小上可能就没有了)。或者file_get_contents()和header( Content-Length: .strlen($ data));

或者可能是一个严重的配置问题?我在主机和本地主机上都对其进行了测试,它们的行为相同。



所以有人知道问题出在哪里吗,或者他们可以建议我使用其他下载脚本或方法吗?



更新:
我在主机上上传了一个大小为1.8 MB的7z文件,下载时文件没有损坏...我越来越难以理解问题所在。



更新:



找到了答案文件顶部的一个值是一些连接方法生成的,在该方法中,我回显了一个值以在一段时间前对其进行检查。



此处提供更多信息:

我认为其中没有内置库用于生成7z或rar文件(例如zip / gzip)的PHP。如果可能,您可能需要使用外部库。


I am using Codeigniter's Download helper for "easy" downloading.

    $this->load->helper('download');
    $file = //get_file_name_from_db
    $data = file_get_contents( upload_path . $file);
    force_download($file, $data);

The problem that I have is that any .zip is downloading correctly while .7z and .rar are not. However when I check the uploaded files to see it they are corrupted or not they are fine (via FTP or in local by simply checking the folders).

To add to the confusion if a file is really small (like 5kb or so) then none of the types (7z and rar) will be corrupted.

For the reference here is the mime types I use in mime.php (that both upload and download helper use)

'zip'   =>  array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
'7z'    =>     array('application/x-7z-compressed','application/x-7z',      'application/7z', 'application/force-download', 'application/octet-stream'),
'rar'   =>  array('application/x-rar-compressed','application/x-rar', 'application/rar', 'application/octet-stream')

THe problem might be at two points, either the mime types (which it probably isn't since as noted, on very small file sizes it works). Or the file_get_contents() and the header("Content-Length: ".strlen($data)); which might not be so since regardless of size .zip will always download correctly.

Or might it be a sever config problem? I tested it both on a host and at localhost and they behave the same.

So does anybody knows what the problem is or can they suggest an alternative download script or method I should use?

UPDATE: I uploaded a 7z file on the host with the size of 1.8 MB and when downloaded the file wasn't corrupted... I am having harder and harder time understanding what is the problem.

UPDATE:

Found the answer it was a value that was on top of the file form the some connected method where I have echoed a value in order to check it some time ago.

For more here: What causes downloaded files to become corrupt?

解决方案

I dont think there is inbuild library in PHP for generating 7z or rar files like zip/gzip. You might need to use external library for this if it is there.

这篇关于Codeigniter下载助手会损坏.7z和.rar文件帮助或替代解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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