dpc57092 2015-08-27 17:10
浏览 221
已采纳

使用opendir()时出现错误

I was creating a wordpress plugin, now i got an error like

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

and these are the files

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();
}
?>

Every time when executing index.php it just creating a zip file with an empty folder in it and exiting

please someone help me to fix this error

  • 写回答

1条回答 默认 最新

  • doushi3454 2015-08-27 17:25
    关注

    opendir() is designed to open local directories (file:// protocol) and since PHP 5.0.0 FTP (ftp://)

    It seems that you're trying to pass an URL (http:// protocol), which is not valid param for opendir

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 依据报错在原代吗格式的基础上解决问题
  • ¥15 在虚拟机中安装flash code
  • ¥15 单片机stm32f10x编写光敏电阻调节3.3伏大功率灯亮度(光强越大灯越暗,白天正常光强灯不亮,使用ADC,PWM等模块)望各位找一下错误或者提供一个可实现功能的代码
  • ¥20 verilog状态机方法流水灯
  • ¥15 pandas代码实现不了意图
  • ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
  • ¥25 LT码在高斯信道下的误码率仿真
  • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?