2015-08-27 55 views
0

我創建一個WordPress插件,現在我得到這樣的錯誤錯誤使用時執行opendir顯示()

Warning: opendir(http://localhost/wordpress/wp-content/uploads/): failed to open dir: not implemented in http://localhost/wordpress/wp-content/plugins/my-plugin/FlxZipArchive.php on line 37 
Warning: readdir() expects parameter 1 to be resource, boolean given in http://localhost/wordpress/wp-content/plugins/my-plugin/FlxZipArchive.php on line 38 

而這些文件

的index.php

<?php 

$upload_dir = wp_upload_dir(); 
$folder_name = $upload_dir['baseurl']; 

//Don't forget to remove the trailing slash 
$the_folder =$foldername; 
$zip_file_name = WP_CONTENT_DIR."/".'uploads.zip'; 
$za = new FlxZipArchive; 
$res = $za->open($zip_file_name, ZipArchive::CREATE); 
if($res === TRUE) { 
    $za->addDir($the_folder, basename($the_folder)); 
    $za->close(); 
} 
else 
    echo 'Could not create a zip archive'; 
?> 

FlxZipArchive .php

<? 
/** 
* FlxZipArchive, Extends ZipArchiv. 
* Add Dirs with Files and Subdirs. 
* 
* <code> 
* $archive = new FlxZipArchive; 
* // ..... 
* $archive->addDir('test/blub', 'blub'); 
* </code> 
*/ 
class FlxZipArchive extends ZipArchive { 
    /** 
    * Add a Dir with Files and Subdirs to the archive 
    * 
    * @param string $location Real Location 
    * @param string $name Name in Archive 
    * @author Nicolas Heimann 
    * @access private 
    **/ 
    public function addDir($location, $name) { 
     $this->addEmptyDir($name); 
     $this->addDirDo($location, $name); 
    } // EO addDir; 
    /** 
    * Add Files & Dirs to archive. 
    * 
    * @param string $location Real Location 
    * @param string $name Name in Archive 
    * @author Nicolas Heimann 
    * @access private 
    **/ 
    private function addDirDo($location, $name) { 
     $name .= '/'; 
     $location .= '/'; 
     // Read all Files in Dir 
     $dir = opendir ($location); 
     while ($file = readdir($dir)) 
     { 
      if ($file == '.' || $file == '..') continue; 
      // Rekursiv, If dir: FlxZipArchive::addDir(), else ::File(); 
      $do = (filetype($location . $file) == 'dir') ? 'addDir' : 'addFile'; 
      $this->$do($location . $file, $name . $file); 
     } 
    } // EO addDirDo(); 
} 
?> 

執行的index.php它只是創造與一個空文件夾中的zip文件,並退出時每次

請別人幫我解決這個錯誤

回答

1

opendir()旨在打開本地目錄(file://協議)和自PHP 5.0.0 FTP(ftp://

看來,你想傳遞一個URL(http://協議),這是不是opendir

+0

所以我應該用什麼執行opendir的insted的()有效PARAM? –

+0

我不確定你想要在這裏實現什麼。我想你想訪問本地目錄,對不對?如果是這樣,比正確的問題是什麼是正確的參數。您應該將常規路徑傳遞到目錄,而不是將URL傳遞給'opendir'函數。就這樣。 –

+0

謝謝你的作品! –