我试图在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) ""
}
但是当我收到$_FILES
数据时,会显示上传的文件数据
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();
}
为什么文件上传不起作用,我该如何解决?
答案 0 :(得分:0)
您的文件路径应如下所示:
$config['upload_path'] = './homologacao/assets/images/promocoes/';
答案 1 :(得分:0)
我做到了!
刚刚在上传路径上设置了DOCUMENT_ROOT
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . 'homologacao/assets/images/promocoes/';
感谢所有帮助我解决问题的人。