CodeIgniter上传类没有返回正确的full_path
。我正在尝试上传图片。我写了这段代码
$config['encrypt_name'] = TRUE;
echo $config['upload_path'] = FCPATH .'contest/videos/';
$config['max_size'] = '1000000000000000';
$config['allowed_types'] = '*';
$config['file_name'] = $_FILES['userfile']['name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
但是它一直询问是否拒绝该许可。当我检查$this->upload->data()
时,我看到full_path
在最后一个文件夹之后没有最后一个斜杠。参见print_r
结果
Array
(
[file_name] => testvdo.mp4
[file_type] =>
[file_path] => /var/www/html/zebra_1975/contest/videos
[full_path] => /var/www/html/zebra_1975/contest/videostestvdo.mp4
[raw_name] => testvdo.mp4
[orig_name] =>
[client_name] =>
[file_ext] =>
[file_size] =>
[is_image] =>
[image_width] =>
[image_height] =>
[image_type] =>
[image_size_str] =>
)
video
中的full_path
后应有一个斜线。我在这里做错了吗?
尝试此操作,希望它可以帮助您正确设置自己的设置。
if (isset($_FILES['profile_img']) && !empty($_FILES['profile_img']['name']))
{
$user_img_path = './public/uploads/images/users/';
$config['upload_path'] = $user_img_path;
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['encrypt_name'] = TRUE;
$config['file_name'] = $img_name;
$config['max_size'] = '9999';
$config['max_width'] = '1524';
$config['max_height'] = '868';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('profile_img')){
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
else{
$image = $this->upload->data();
print_r($image);
}
}
我正在我的项目中使用它因此,对我来说,我使用了它并正在为我工作
$user_img_path = './public/uploads/images/users/';
所以尝试一下