我在stackoveflow找到了一些关于如何压缩特定文件的代码,但是特定文件夹怎么样?
Folder/
index.html
picture.jpg
important.txt
Run Code Online (Sandbox Code Playgroud)
在里面My Folder,有文件.在压缩之后My Folder,我还要删除文件夹的全部内容important.txt.
在堆栈找到这个
我需要你的帮助.谢谢.
我试图将文件从一个文件夹保存到另一个文件夹.zip文件夹放在不同的目录中.我写了以下代码:
archive.php
<?php
$zip = new ZipArchive();
$zip->open('example.zip', ZipArchive::CREATE);
$srcDir = "/home/sam/uploads/";
$files= scandir($srcDir);
//var_dump($files);
unset($files[0],$files[1]);
foreach ($files as $file) {
$zip->addFile("{$file}");
}
$zip->close();
?>
Run Code Online (Sandbox Code Playgroud)
但遗憾的是我无法创建.zip文件夹.我错过了什么步骤?
我正在自学php,我正在创建一个示例测试站点,让用户输入文件代码,用于确定要下载的文件夹的文件路径.我下面的代码只下载一个文件.我现在想要的是下载并压缩整个目录.请帮忙.先感谢您
<h3>Search Client File</h3>
<form method="post" action="#" id="searchform">
Type the Image Code:<br><br>
<input type="text" name="icode">
<br>
<input type="submit" name="submit" value="Search">
</form>
<?php
$fcode=$_POST["icode"];
if (!empty($fcode))
{
$file="/var/www/website/$fcode.tif";
if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
ob_end_flush();
readfile($file);
}
else
{
echo "The file $fcode.tif does not exist";
}
}
else
{
echo "No Values";
}
?>
Run Code Online (Sandbox Code Playgroud)