2013-03-15 64 views
0

所以我有以下代碼:zip壓縮包不開放

$z = new ZipArchive(); 
$zopen = $z->open('https://github.com/AdamKyle/Aisis-Framework/archive/Aisis1.1.7.zip', 4); 
if ($zopen === true) { 
    for ($i = 0; $i < $zip->numFiles; $i++) { 
     $filename = $zip->getNameIndex($i); 
     var_dump($filename); 
    } 
} else { 
    echo "fail"; 
} 
exit; 

它不斷造成故障。我提供的URL在瀏覽器中適用於我,但不在上面的代碼中。這是怎麼回事?

更新

有人問我什麼的resaults:

var_dump(stream_get_wrappers());

是,他們是波紋管

array (size=12) 
    0 => string 'https' (length=5) 
    1 => string 'ftps' (length=4) 
    2 => string 'compress.zlib' (length=13) 
    3 => string 'compress.bzip2' (length=14) 
    4 => string 'php' (length=3) 
    5 => string 'file' (length=4) 
    6 => string 'glob' (length=4) 
    7 => string 'data' (length=4) 
    8 => string 'http' (length=4) 
    9 => string 'ftp' (length=3) 
    10 => string 'phar' (length=4) 
    11 => string 'zip' (length=3) 
+0

很有可能您的PHP或ZipArchive類設置爲不允許從流中打開文件。你應該檢查文檔,看ZipArchive是否有方法告訴你爲什麼'open()'調用失敗。 – Cfreak 2013-03-15 20:33:38

+0

如果保存.zip文件並指向本地位置,會發生什麼情況? – 2013-03-15 20:35:23

+0

它是int 11,這意味着它失敗。 – TheWebs 2013-03-15 20:44:34

回答

1

具有讀之後,我相信ZipArchive不支持通過URI打開zip文件。

爲了與拉鍊的工作,你首先需要將其複製到本地磁盤...

$content = file_get_contents('https://github.com/AdamKyle/Aisis-Framework/archive/Aisis1.1.7.zip'); 
file_put_contents('/tmp/name.zip', $content); 
$zip = new ZipArchive(); 
$zip->open('/tmp/name.zip'); 

確保allow_url_fopen INI設置被啓用。