2010-08-18 74 views
0

被复制目前我正在试图创建一个内容上传系统,虽然有错误正在从网页制作时,我选中相应的文件夹中的内容为空邮编文件夹的内容不

$chapterZip = new ZipArchive(); 

if ($chapterZip->open($_FILES['chapterUpload']['name'])) 
{ 
    for($i = 0; $i < $chapterZip->numFiles; $i++) 
    { 
    $pictureName = $chapterZip->getNameIndex($i); 
    $fileOpened = $chapterZip->getStream($pictureName); 
    if(!$fileOpened) exit("failed\n"); 
    while (!feof($fileOpened)) { 
     $contents = fread($fileOpened, 8192); 
     // do some stuff 
     if(copy($contents,"Manga/".$_POST['mangaName']."/".$_POST['chapterName']."/".$pictureName."")) 
     { 
      if(chmod("Manga/".$_POST['mangaName']."/".$_POST['chapterName']."/".$pictureName."", 0664)) 
      { 
       $errmsg0.= "File successfully copied<br/>"; 
      } 
      else 
      { 
       $errmsg0.= "Error: failed to chmod file<br/>"; 
      } 
     } 
     else 
     { 
      $errmsg0.= "Error: failed to copy file<br/>"; 
     } 
    } 
    fclose($fileOpened); 
    } 

}

这个问题的任何帮助,将不胜感激

+0

的代码非常难以阅读。你能更详细地解释你在这里做什么吗? – 2010-08-18 08:05:27

+0

你得到一个错误或不? 此外,你混合阅读字节($内容)与文件复制,我怀疑它可以工作。 省略一半的代码也无济于事。 – PhiLho 2010-08-18 08:15:58

+0

@Pekka 代码从站点读取上传的zip文件,打开文件,并通过内容将循环复制到在类中早先创建的文件夹中。 @PhiLho 我没有得到任何错误,现在我已经在问题中包含了整个方法,只是认为它与我所问的问题有点不相干。 – dbomb101 2010-08-18 08:42:01

回答

1

我看着它进一步发现一个相当简单的方法来提取文件,在PHP在线手册

$zip = new ZipArchive; 
$res = $zip->open('test.zip'); 
if ($res === TRUE) { 
    echo 'ok'; 
    $zip->extractTo('test'); 
    $zip->close(); 
} else { 
    echo 'failed, code:' . $res; 
} 
0

我不知道如果这能帮助你,但我昨天经过一些信息,我发现寻找递归拉上写这个剧本。

function zip($source, $destination) 
    { 
     if (file_exists($source) === true) 
     { 
      $zip = new ZipArchive(); 

      if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) 
      { 
       $source = realpath($source); 

       if (is_dir($source) === true) 
       { 
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); 

        foreach ($files as $file) 
        { 
         $file = realpath($file); 

         if (is_dir($file) === true) 
         { 
          $zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); 
         } 

         else if (is_file($file) === true) 
         { 
          $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file)); 
         } 
        } 
       } 

       else if (is_file($source) === true) 
       { 
        $zip->addFromString(basename($source), file_get_contents($source)); 
       } 
      } 

      return $zip->close(); 
     } 
    } 

发现它在一些网站上,我不记得在哪里。适应它一点点。

用法:zip('mydir /','myZipFile.zip');

BR, 保罗Peelen

+0

'if(is_true($ foo)=== true){$ isIsTrueTrue = true; $ isIsIsTrueTrueBoolean = is_boolean($ isIsTrueTrue)=== true; }' – janmoesen 2010-08-18 11:28:26