强制下载失败后断开链接Codeigniter [英] Unlink after force download not working Codeigniter
问题描述
强制下载后我无法删除我的文件。下面是代码
i was unable to remove my file after force download.below is the code
public function download($id)
{
$this->load->helper('download');
$filepath = "url/" . $id;
force_download("file-name", $filepath);
ignore_user_abort(true);
unlink($filepath);
}
在这方面请及时告诉我。
Kindly update me on this regard.
推荐答案
我遇到了同样的情况。因此,我只想分享以下信息,以帮助有需要的人。
I have came across same situation. So i just want to share the following information if that helps people in need.
实际上
force_download( file-name,$ filepath) ;
在这段代码之后您将不会执行任何操作,因为force_download方法具有 header 和 exit 调用。
因此,如果要删除正在下载的文件,可以在调用 force_download 方法之前将其删除。
So if you want to delete file which is being downloaded, you can delete it before calling force_download method.
有些人会怀疑我们在下载文件之前如何删除它。实际上,force_download方法中的第二个参数实际上是正在下载的文件的内容。一旦有了该文件,就不需要该文件。
Some people will be having a doubt like how can we delete a file before downloading it.Well actually the second parameter in force_download method is actually the content of the file being downloaded. Once you have that you do not require the file.
$file_content = file_get_contents($file_path); // Read the file's contents
if(file_exists($file_path)){
unlink($file_path);
}
force_download($filename, $file_content);
这篇关于强制下载失败后断开链接Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!