ZipArchive は、解凍しようとしているファイルを見つけることができません。私は何を間違っていますか?これをすべてdispatch_asyncで実行しようとしていますが、それは私の問題ですか?
「zipファイルが見つかりませんでした」と出てしまいます。私のログで。そして、アプリ データ ファイルに作成されているはずのディレクトリを確認すると、どこにも見つかりません。zipファイルがどのように存在するか。
これは、私がやろうとしていることとよく似たチュートリアルへのリンクです。必要なライブラリも追加しました。
エラー処理を含むようにリクエストごとに編集されたコード:
NSLog(@"Got the data!");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
//Save the data
NSLog(@"Saving");
NSString *dataPath = [path stringByAppendingPathComponent:@"TKAPlacesImages.zip"];
dataPath = [dataPath stringByStandardizingPath];
NSError *error = nil;
[urlData writeToFile:dataPath options:0 error:&error];
if(!error)
{
if (![defaults objectForKey:@"places images path"]) {
[defaults setObject:path forKey:@"places images path"];
[defaults synchronize];
}
ZipArchive* za = [[ZipArchive alloc] init];
if( [za UnzipOpenFile:dataPath] )
{
BOOL ret = [za UnzipFileTo:path overWrite: YES];
if (NO == ret){} [za UnzipCloseFile];
NSLog(@"Successful unzip of: %@",@"/Library/Caches/TKAPlacesImages.zip");
}
else
{
NSLog(@"Could not find zip file.");
}
}
else
{
NSLog(@"Error saving file %@",error);
}
追加された PHP コード
function zip_image_files($images) {
// Prepare File
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
$imagesCount = count($images);
$imagesString = '';
for($i=0; $i < $imagesCount; $i++)
{
// Stuff with content
$imagesString = ".." . $images[$i];
if(file_exists($imagesString))
{
$zip->addFile($imagesString);
}
else
{
echo $imagesString;
}
}//end for
// Close and send to users
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="file.zip"');
readfile($file);
unlink($file);
}
//end function
Edit My 関数は 19.2MB の zip ファイルを返します。ただし、私のアプリ データ ファイルでは、zip ファイルは 0 バイトです。