我在窗户上
我正在使用PHING压缩一些文件
我有很多东西被压缩
压缩工作,但在压缩文件中包含特定phing文件集的工作除外
当我调试时,我可以在phing的ZIP任务中看到ZipArchive :: close返回false.错误字符串显示"权限被拒绝".在手册中声明close()是实际写入文件的内容.
它不是时间耦合,换句话说,它发生在这个是第一个,最后一个或其他什么.所有其他的工作.这个似乎没什么不同.
这是我的构建文件:http://pastebin.org/84786(好一个月)
问题出在第251行.在它之前和之后的zip任务都可以正常工作.在调试器中,我可以看到大约150个文件被添加到zip中.我已经验证了调试器中所有正确的路径.
构建似乎在linux上运行良好.
当我右键单击zip文件所在的文件夹时,只读复选框为"蓝色",未选中或未选中.我保持选中或取消选中并按下确定并返回文件夹的属性,复选框再次为"蓝色".显然这是设计(http://support.microsoft.com/kb/326549),这似乎不是问题,因为它只发生在那个文件.
另一个奇怪的事情是,如果我转到第252行并将文件集更改为指向例如来自其上方"importer"模块的文件,则会创建zip.然而,第236行的.tar.gz相同的文件集证明每次都能正常工作.所以它只发生在zip任务的特定文件集中.该文件集适用于tar任务.实际上,在它下面的"package"注释下的所有任务也引用了那些文件,但tar.gz文件却没有.
是什么赋予了?
另外:新观察...在两台Windows机器上看起来如果我快速刷新文件视图我可以看到myzipfile.zip.tmp正在构建,但myzipfile.zip永远不会被创建.
在linux上我只是仔细检查了一切是否完美无缺.去搞清楚.
我正在尝试从wordpress中的帖子附件创建一个zip文件.
我已尝试过以下两种方法 - 但它没有结果(没有错误消息,没有创建文件) - 我做错了什么(再次......)
我不认为那些是wordpress中的帖子附件的事实与它有关 - 因为那些方法也失败了普通文件.为什么? - >看到答案.
$files_to_zip = array();// create files array
//run a query
$post_id = get_the_id();
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post_id
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$files_to_zip [] = wp_get_attachment_url( $attachment->ID ); // populate files array
}
}
print_r($files_to_zip);
$zip = new ZipArchive;
$zip->open('file.zip', ZipArchive::CREATE);
foreach ($files_to_zip as $file) {
$zip->addFile($file);
}
$zip->close();
Run Code Online (Sandbox Code Playgroud)
还有这个方法:
$files_to_zip = …Run Code Online (Sandbox Code Playgroud) 我正在使用CodeIgniter和PHPExcel来读取和写入excel文件.
在localhost中一切正常,但是当我将我的PHP CodeIgniter应用程序上传到pagodabox中的服务器时,当我尝试从excel文件中读取数据时,我得到了以下消息.
Fatal error: Uncaught exception 'Exception' with message 'ZipArchive library is not enabled' in /var/www/application/libraries/PHPExcel/Reader/Excel2007.php
Run Code Online (Sandbox Code Playgroud) failed to open stream: Is a directory尝试使用 PHP 解压缩文件时,我不断收到错误消息。
这通常是目标路径的问题。
但是,就我而言,目标很好:我可以使用相同的代码解压缩不同的文件,或者不用 PHP 解压缩同一个文件。
该ZipArchive :: extractTo文档没有帮助。其他 SO 线程也没有针对此错误消息。
仅供参考,这是一个问答帖子。
这是评论中要求的源代码。我公开分享了 Dropbox 链接,因为这取决于 ZIP 输入的格式(/ZIP 文件中的路径,请参阅答案。)
/** Config **/
$url = 'https://www.dropbox.com/sh/nx5792q9syppaoo/AAAJZBWlGNAd_EkmQaFvEwe0a?dl=1';
/** Where to save **/
$zipped = ABSPATH . 'tmp/updates/dialogues.zip'; /* Keep in mind this is public-facing. */
$outputdirectory = ABSPATH . 'tmp/updates/testing'; /* The trailing slash is optinal. */
/** Download the dialogues **/
echo 'Fetching the dialogues...<br>';
if ( ( …Run Code Online (Sandbox Code Playgroud) 我想从zip文件中仅提取图像,但我也希望它提取子文件夹中的图像.如何根据我的代码实现这一点.注意:我不是想在这里保留目录结构,只是想要提取zip中找到的任何图像.
//extract files in zip
for ($i = 0; $i < $zip->numFiles; $i++) {
$file_name = $zip->getNameIndex($i);
$file_info = pathinfo($file_name);
//if ( substr( $file_name, -1 ) == '/' ) continue; // skip directories - need to improve
if (in_array($file_info['extension'], $this->config->getValidExtensions())) {
//extract only images
copy("zip://" . $zip_path . "#" . $file_name, $this->tmp_dir . '/images/' . $file_info['basename']);
}
}
$zip->close();
Run Code Online (Sandbox Code Playgroud)
编辑
我的代码工作正常,我需要知道的是如何使ziparchive进入子目录
在我的应用程序中,我有一个使用zip存档操作的类System.IO.Compression.ZipArchive.现在我想将存档的条目保存到文件中.我怎样才能做到这一点?我知道我可以将Stream存档与存档相关联,但在我的情况下,存档会创建无流数据,但我无法更改代码:
var archive = ZipFile.Open(fileName, ZipArchiveMode.Create);
// add entries
// how can I save it to file now?
Run Code Online (Sandbox Code Playgroud) 当我尝试删除压缩目录中的文件时,出现这个奇怪的错误:
ZipArchive::close(): Renaming temporary file failed: Permission denied in /MyDirectory/myphpscript.php
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$compressedDirectoryPath = '/Users/Shared/SampleZip.zip';
$zip = new ZipArchive();
if ($zip->open($compressedDirectoryPath) === true) {
if ($zip->deleteName('SampleZip/samplefile.txt') === true) {
echo 'File deleted';
}
}
$zip->close(); // the error is pointing here
?>
Run Code Online (Sandbox Code Playgroud)
执行echo成功并打印File deleted。我运行的是 Mac,压缩目录的权限适用read & write于所有用户。可能是什么问题?
需要一些 Laravel zip 文件的帮助。我在公共文件夹中有一个文件夹,我想在用户单击按钮时创建该文件夹的 zip(temp_file 文件夹)。
public function testing()
{
$public_dir = public_path('temp_file/');
$zipFileName = 'myZip.zip';
$zip = new ZipArchive;
if ($zip->open($public_dir . '/' . $zipFileName, ZipArchive::CREATE) === TRUE) {
$zip->addFile('file_path', 'file_name');
$zip->close();
}
$headers = array('Content-Type' => 'application/octet-stream');
$filetopath = $public_dir . '/' . $zipFileName;
}
Run Code Online (Sandbox Code Playgroud)
但它似乎没有创建 zip 文件,我无法下载它。请需要一些帮助
我创建了一个 BizTalk 自定义管道组件,它将所有消息部分压缩到一个 zip 流中。在一些失败之后,我在一个单独的测试项目中创建了以下测试方法。
基本上,我得到一个 XML 文件,其中包含一个文件名和一个 UUID,我用它来调用存储过程并获取数据库条目的 Base64 编码内容。base64 内容似乎有效,因为在对其进行解码并将其保存到文件系统后,Windows 资源管理器可以毫无问题地读取文件。
将存档流保存到文件系统后,当我尝试提取文件时,我从 7Zip 收到以下错误消息:“数据意外结束”。如果我尝试仅使用 7Zip 打开文件,则没有问题。我什至可以从 7Zip 资源管理器中打开文件。
如果我尝试使用以下代码从 C# 读取文件,则会收到错误消息:“找不到中央目录记录的结尾。”
解压代码:
private static void ReadDat() {
var path = @"...\zip\0e00128b-0a6e-4b99-944d-68e9c20a51c2.zip";
var stream = System.IO.File.OpenRead(path);
// End of Central Directory record could not be found:
var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, false);
foreach(var zipEntry in zipArchive.Entries) {
var stream = zipEntry.Open();
Console.WriteLine(stream.Length);
}
}
Run Code Online (Sandbox Code Playgroud)
邮政编码:
private static void StreamUuidList() {
var path = @"...\2017-08-05T132705.xml";
var xdoc = XDocument.Load(System.IO.File.OpenRead(path)); …Run Code Online (Sandbox Code Playgroud) 我从 api 下载了一个 ziparchive,其中包含 gzipped 文件,我需要获取 gz 文件并保存到 s3。不想解压缩或任何东西。只需移动到S3。
当我打开存档时,它有一个带有随机数的文件夹 /12345/file1.gz 和许多文件 /12345/file2.gz 等。
我尝试过 yauzl 和 adm-zip,但不明白如何获取存档中的每个条目并发送到 s3。我有 s3-stream-upload 包,我可以用它来发送。就是做对了。谢谢你的帮助
yauzl.open("output.zip", {lazyEntries: true}, function(err, zipfile) {
if (err) console.error('zip err: ', err);
console.log(zipfile);
//upload.write(zipfile);
zipfile.readEntry();
zipfile.on("entry", function(entry) {
// file entry
zipfile.openReadStream(entry, function(err, readStream) {
if (err) console.error('readstream err: ', err);
readStream.on("end", function() {
zipfile.readEntry();
});
console.log(entry);
readStream.pipe(upload) //upload is an s3-upload-stream
.on('finish', function() { console.log('finished'); })
.on('error', function(err) { console.error('stream err: ',err); });
});
});
});
Run Code Online (Sandbox Code Playgroud)
这让我在结束后写入错误,我认为 bcz …