gpt4 book ai didi

php - Codeigniter 上传图片 - 上传路径似乎无效

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:09:51 24 4
gpt4 key购买 nike

我在使用 codeigniter 上传库上传图片时遇到问题,我一直收到错误,

The upload path does not appear to be valid.

我尝试上传的文件路径如下,

$config['upload_path'] = './media/images/site';

当我点以下内容时,

die(var_dump(is_dir($config['upload_path'])));

我得到以下返回,

bool(true)

该文件夹也是可写的(777),所以我不确定我哪里出错了,下面是我的上传代码,

$config['upload_path'] = './media/images/site';
//die(realpath($config['upload_path']));
//die(var_dump(is_dir($config['upload_path'])));
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1500';
$config['max_width'] = '390';
$config['max_height'] = '269';

$this->load->library('upload',$config);
if ( ! $this->upload->do_upload() && $_FILES['userfile']['error'] != 4)
{
$data['error'] = $this->upload->display_errors();
$this->template->build('/admin/pages/about_us', $data);
}
else
{
$image = $this->upload->data();
if(empty($image['file_name'])) {
$image['file_name'] = $this->formbuilder->defaults['page_image'];
}
$page = array(
//'page_title' => $this->input->post('page_title'),
//'page_slug' => $this->input->post('page_slug'),
'page_content' => $this->input->post('page_content'),
'page_image' => $image['file_name'],
'date_created' => date("Y-m-d h:i:s"),
'created_by' => 1
);

if($this->pages_model->insert($this->security->xss_clean($page)))
{
redirect('/admin/dashboard');
}
}

我看不到任何明显会阻止文件上传的东西,下面是我项目的文件夹结构

/application
/system
index.php
.htaccess
/media
/images
/site
/admin
/css
/js

如果有人能阐明我的问题,那就太好了。

为任性的反对者编辑

什么会导致这个问题?

(有个疑问,反正好像不够明显)

最佳答案

尝试在库加载行之前添加这一行:

 // Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);

不要忘记在模板中添加这一行:

<?php echo form_open_multipart('upload/do_upload');?>

关于php - Codeigniter 上传图片 - 上传路径似乎无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8121382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com