我在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文件夹.我错过了什么步骤?
我想解压导演.
这意味着我有一个压缩的目录名xxx.zip.在手册册我对上压缩目录中点击并做解压的文件夹,然后我买了名的解压缩dirtectory xxx并在此目录中有一个相同的目录xxx.在子文件夹将包含的文件.
这意味着,xxx-> xxx->文件这是解压缩文件夹的heirarchi.
因此,在我的网站中,我想使用PHP代码解压缩目录.
我怎样才能做到这一点?我只需要xxx->files不是xxx->xxx->files结构.
我怎样才能做到这一点?
我为我的网站写了一个基本的内容管理系统,包括一个管理面板.我理解基本文件IO以及通过PHP进行复制,但是我对从脚本调用的备份脚本的尝试失败了.我试过这样做:
//... authentication, other functions
for(scandir($homedir) as $buffer){
if(is_dir($buffer)){
//Add $buffer to an array
}
else{
//Back up the file
}
}
for($founddirectories as $dir){
for(scandir($dir) as $b){
//Backup as above, adding to $founddirectories
}
}
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.
我知道我可以使用FTP来做到这一点,但我想要一个完全服务器端的解决方案,只要有足够的授权就可以在任何地方访问.
我的系统生成一个包含下一个文件和子文件夹的文件夹

我正在使用此代码创建一个odt文件.当我使用此代码运行我的系统,通过Apache + PHP和Ubuntu 12.04将子文件夹和文件压缩到test.odt文件时,odt文件就可以了.但是当我尝试通过IIS + PHP和Windows将一个压缩到test.odt文件时,odt文件无效.我知道不行,因为当我用LibreOffice打开odt文件时,我得到错误输入/输出一般错误. 这里是odt文件.
当我提取通过Windows生成的odt文件时,文件夹和文件具有相同的图片形式.我正在寻找谷歌,也许问题是mimetype编码.
我将如何修改代码1,以便解决我的问题?
编辑
我用下面的代码使用这个文件夹,但我的odt文件中只有"PKÜNTEBasic/PKÜNTEúミ,lÓR/ Basic/script-lc.xmleマAoÂ0".这里的例子.
<?php
$wordtemplatedownloadpath = "siscons\\test\\wordtemplatedownload\\";
Zip($wordtemplatedownloadpath . "pasta3", $wordtemplatedownloadpath . "test.odt");
force_download("test.odt", $wordtemplatedownloadpath . "test.odt");
//echo "<a href=test/wordtemplatedownload/test.odt>" . "Download Force". "</a>";
function Zip($source, $destination)
{
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
//echo $source;
if (is_dir($source) === true) {
$files …Run Code Online (Sandbox Code Playgroud) 我想tar.gz使用PHP 压缩(动态)格式化目录.我知道它可以使用exec或使用this code(使用ZIP格式)但我的主机不支持exec并且没有安装PHP的zip扩展.
在搜索互联网后,我遇到了this PHP code:
<?php
// Computes the unsigned Checksum of a file’s header
// to try to ensure valid file
// PRIVATE ACCESS FUNCTION
function __computeUnsignedChecksum($bytestring) {
for($i=0; $i<512; $i++)
$unsigned_chksum += ord($bytestring[$i]);
for($i=0; $i<8; $i++)
$unsigned_chksum -= ord($bytestring[148 + $i]);
$unsigned_chksum += ord(" ") * 8;
return $unsigned_chksum;
}
// Generates a TAR file from the processed data
// PRIVATE ACCESS FUNCTION
function tarSection($Name, $Data, $information=NULL) {
// …Run Code Online (Sandbox Code Playgroud) 如何使用PHP将目录转换为zip文件?
谢谢.
我正在尝试使用基于数组结构的目录树创建一个zip文件。
当我需要从目录树创建一个zip文件时,我已经使用了这个答案,但是在这种情况下,所有文件都位于同一目录中,并且目录树基于数据库中的其他数据。
我检查了所有文件的路径都正确,并且foreach循环正常工作。$ zip-> close发生错误。
这就是代码(原始数组在每个级别都有很多条目):
$zip_array = array( 'Level 1' => array(
'Level 2' => array (
'file 1' => '/var/www/html/pdf/683026577.pdf',
'file 2' => '/var/www/html/pdf/683026578.pdf'
'file 3' => '/var/www/html/pdf/683026579.pdf'
)
)
);
$destination = 'testzip.zip';
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
echo "fail";
}
foreach ($zip_array as $key => $level2){
$lev1 = '/'.$key.'/';
$zip->addEmptyDir($lev1);
foreach ($level2 as $key => $level3){
$lev2 = $level1 . $level2.'/';
$zip->addEmptyDir(lev2);
foreach ($level3 as $key => $file){
$lev3 = $lev2 …Run Code Online (Sandbox Code Playgroud) 我想使用php创建给定文件夹中所有文件的快照,然后压缩它.
我怎样才能做到这一点.正在将内置函数压缩到php.也有压缩的替代方案.
您为代码准备了什么样的文件备份系统.我这样做是为了一个开源应用程序,所以它不是备份我的特定系统,所以它必须纯粹用PHP,因为人们不会总是知道如何安装某些应用程序.
多谢你们.
php ×9
zip ×5
backup ×2
directory ×2
arrays ×1
compression ×1
filesystems ×1
gzip ×1
tar ×1
unzip ×1
ziparchive ×1