0

Im trying to upload multiple files from a single form but for some reason i get "The upload path does not appear to be valid." I have checked permissions and they are correct, so i dont know if this is a problem with the images it self.. these are the functions i use to create the images

<input type="file" name="images[]" multiple id="img"></input>

function upload_image(){

    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = 2*1024;
    $config['max_width']  = '1024';
    $config['max_height']  = '1024';
    $config['remove_spaces'] = TRUE;

    $this->load->library('upload', $config);

    if (!$this->upload->do_upload('images'))
    {
        $error = array('error' => $this->upload->display_errors());
        return $error;
    }   
    else
    {
        for($i = 0, $t = count($_FILES['images']); $i < $t; $i++) {

            $id = $this->files->create_thumb($i);

        }
    }
}

 function create_thumb($i){

    $file = $this->upload->data();
    $files = $file['file_name'];
    $fields = array('files' => $files[$i]);

    print_r($fields);
    exit;

    for ($i = 0; $i < count($files); $i++) {

    $config['image_library'] = 'gd2';
    $config['source_image'] = 'files/images/'.$files[$i];
    $config['new_image']    = 'files/images/thumbs/'.$files[$i];
    $config['thumb_marker'] = '';
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['width']     = 120;
    $config['height']   = 120;

    $this->load->library('image_lib'); 
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    $this->image_lib->clear();

    }

}
4

1 回答 1

1

将您的配置移动到config/upload.php. 作为替代解决方案,您可以在加载库后使用以下代码行来初始化配置:

$this->upload->initialize($config);

文档中:

如果您不想使用上述方法设置首选项,则可以将它们放入配置文件中。只需创建一个名为upload.php 的新文件,在该文件中添加$config 数组。然后将文件保存在:config/upload.php,它会被自动使用。如果您将首选项保存在配置文件中,则不需要使用 $this->upload->initialize 函数。

要检查您的目录是否可以通过 PHP 访问,您可以使用is_dir()

var_dump(is_dir('/path/to/upload/folder/')); 

希望这可以帮助!

于 2013-07-11T20:14:15.407 回答