【发布时间】:2016-02-25 21:37:31
【问题描述】:
我正在尝试使用 codeigniter 上的上传类上传文件,但它给我一个错误,提示文件路径无效。
我打印了$this->upload->data,它没有显示文件数据,但是我设置的上传文件夹存在并显示在上面。
array(14) {
["file_name"]=> string(0) ""
["file_type"]=> string(0) ""
["file_path"]=> string(36) "homologacao/assets/images/promocoes/"
["full_path"]=> string(36) "homologacao/assets/images/promocoes/"
["raw_name"]=> string(0) ""
["orig_name"]=> string(0) ""
["client_name"]=> string(0) ""
["file_ext"]=> string(0) ""
["file_size"]=> string(0) ""
["is_image"]=> bool(false)
["image_width"]=> string(0) ""
["image_height"]=> string(0) ""
["image_type"]=> string(0) ""
["image_size_str"]=> string(0) ""
}
但是当我得到$_FILESdata时,它会显示上传的文件数据
array(1) {
["imagem"]=> array(5) {
["name"]=> string(68) "3bf514d6cbb31410ee47e8cbcc79c81588a6740fb4264209a1531077e0fcc0a9.jpg"
["type"]=> string(10) "image/jpeg"
["tmp_name"]=> string(14) "/tmp/phpomUcFo"
["error"]=> int(0)
["size"]=> int(3571)
}
}
我仔细检查了我的代码,我认为我设置正确
/*code slice with the upload part */
$config['upload_path'] = 'homologacao/assets/images/promocoes/';
$config['allowed_types'] = 'png|jpg|gif';
$config['max_size'] = '1024';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
$field_name = 'imagem';
if ($this->upload->do_upload($field_name)) {
/* do stuff */
} else {
var_dump($this->upload->data());
var_dump($this->upload->display_errors());
var_dump($_FILES);
die();
}
为什么文件上传不起作用,我该如何解决?
【问题讨论】:
-
你在 display_errors() 中得到了什么
-
类似“无效的上传文件路径”
标签: php codeigniter file-upload