致命错误:调用未定义的方法UploadHandler

时间:2014-03-03 17:26:27

标签: php

我正在使用jQuery File Upload而我只将UploadHandler()类的位置从HOME/server/php/UploadHandler.php更改为HOME/index.php但我收到此错误:

index.php:1438: Fatal Error: Call to undefined method UploadHandler::get_file_object [array_map]

我的index.php:

<?php

error_reporting(E_ALL | E_STRICT);

class UploadHandler
{
    protected $options;

    // PHP File Upload error message codes:
    // http://php.net/manual/en/features.file-upload.errors.php
    protected $error_messages = array(

    etc....

    protected function get_file_object($file_name) {
        if ($this->is_valid_file_object($file_name)) {
            $file = new stdClass();
            $file->name = $file_name;
            $file->size = $this->get_file_size(
                $this->get_upload_path($file_name)
            );
            $file->url = $this->get_download_url($file->name);
            foreach($this->options['image_versions'] as $version => $options) {
                if (!empty($version)) {
                    if (is_file($this->get_upload_path($file_name, $version))) {
                        $file->{$version.'Url'} = $this->get_download_url(
                            $file->name,
                            $version
                        );
                    }
                }
            }
            $this->set_additional_file_properties($file);
            return $file;
        }
        return null;
    }

    etc...

    protected function get_file_objects($iteration_method = 'get_file_object') {
        $upload_dir = $this->get_upload_path();
        if (!is_dir($upload_dir)) {
            return array();
        }
        return array_values(array_filter(array_map(
            array($this, $iteration_method),
            scandir($upload_dir)
        )));
    }

}

$upload_handler = new UploadHandler();

?>

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

将此功能设为“静态”

protected function get_file_object($file_name) {

as

protected static function get_file_object($file_name) {