![](/img/trans.png)
[英]How to create a ZIP file using PHP and delete it after user downloads it?
[英]How to delete zip file with PHP
在我的项目中,我已经用ajax下载了17111611185.zip文件。
下载完zip文件后,我想从Linux服务器上删除该文件。
因此,在window.location = data之后,再次调用ajax以将17111611185.zip传递到服务器。
$.ajax({
type:'POST',
data:{files:files},
url:'oat.php',
success:function(data){// data is 17111611185.zip
window.location=data;
//2017-12-19delete zip file
$.ajax({
type:'POST',
data:{delFile:data},
url:'delFileoat.php',
success:function(data){
}
});
}
});
delFileoat.php代码为:
<?php
if(isset($_POST['delFile'])){
$delFile=$_POST['delFile'];
unlink($delFile);
}
?>
但很不幸,找不到返回消息17111611185.zip。 并且删除进度失败。
看来没错。 当我只下载文件而不删除文件时,例如:
$.ajax({
type:'POST',
data:{files:files},
url:'oat.php',
success:function(data){// data is 17111611185.zip
window.location=data;
}
});
可以。 但是失败,添加删除代码时。
我认为上传的文件位于tmp文件夹中,可以通过
ini_get('upload_tmp_dir');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.