我的一个网站也有非常相似的功能。 就像在下载/取消下载后删除随机创建的文件夹和zip文件一样。 我在这里尝试解释,可能有人认为它有用。
skin.php:
此页面包含下载链接,例如“ [http://mysite.com/downoload/bluetheme”]
.htaccess:
我在htaccess文件中遵循以下规则,将下载请求重定向到php文件。 [download.php]。
RewriteRule ^download/([A-Za-z0-9]+)$ download.php?file=$1 [L]
download.php:
include "class.snippets.php";
$sn=new snippets();
$theme=$_GET['file'];
$file=$sn->create_zip($theme);
$path="skins/tmp/$file/$file.zip";
$config_file="skins/tmp/$file/xconfig.php";
$dir="skins/tmp/$file";
$file.=".zip";
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$file");
header("Pragma: no-cache");
header("Expires: 0");
readfile($path);
//remove file after download
unlink($path);
unlink($config_file);
rmdir($dir);
因此,根据要求download.php将使用摘要类创建具有随机名称的目录。 在目录内,它将创建一个zip文件。 下载/取消请求后,所有文件和目录将被删除。