“上传路径似乎无效".Codeigniter 文件上传不起作用 [英] "The upload path does not appear to be valid". Codeigniter file upload not working

查看:23
本文介绍了“上传路径似乎无效".Codeigniter 文件上传不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经被困在这一点上很长时间了,即使在阅读了许多帖子后,我也没有找到解决方案.

我正在制作一个测验的界面,在管理界面中,我需要将图像上传到文件夹并将图像名称上传到数据库.我可以处理其他事情,但图片上传困扰了我很长时间.

请看下面我的代码.

表格

<?php echo form_open_multipart('admin/update_question');?><?php echo form_hidden('questionid', $question->level);?><?php echo form_label('Comment', 'comment');?><div class="输入"><?php$arr_comment = 数组('名称' =>'评论','id' =>'评论','价值' =>$问题->评论);echo form_textarea($arr_comment);?>

<br/><?php echo form_label('Answer', 'answer');?><div class="输入"><?php$arr_answer = 数组('名称' =>'回答','id' =>'回答','尺寸' =>'10000','价值' =>$question->answer);echo form_input($arr_answer);?>

<br/><?php echo form_label('Image', 'userfile');?><div class="输入"><?php$arr_image = 数组('名称' =>'用户档案','id' =>'用户档案','价值' =>'');echo form_upload($arr_image);?>

<br/><?php$arr_button = 数组('名称' =>'提交','价值' =>'更新问题','类' =>'btn 初级大');?><div class="输入"><?php echo form_submit($arr_button);?>

<br/><?phpecho form_close();如果($错误!= '')echo '<div class="alert-message error">'.$错误.'

';回声验证错误();?>

我试过运行一个 js,它在上传框中返回文件名,它确实返回了它.

控制器

公共函数update_question() {$comment = $this->input->post('comment');$answer = $this->input->post('answer');echo var_dump(is_dir(base_url().'uploads/'));/** 上传图片*/$config['upload_path'] = base_url().'/uploads/';$config['allowed_types'] = 'gif|jpg|png';$config['max_width'] = 0;$config['max_height'] = 0;$config['max_size'] = 0;$config['encrypt_name'] = TRUE;$this->load->library('upload', $config);如果 ( !$this->upload->do_upload()){$error = array('error' => $this->upload->display_errors());打印_r($错误);}别的{$arr_image = array('upload_data' => $this->upload->data());打印_r($arr_image);}$questionid = $this->input->post('questionid');$question_data = 数组('评论' =>$评论,'答案' =>$答案);$this->load->model('adminmodel', 'admin');$question_data = $this->admin->update_question_data($questionid, $question_data);//重定向('管理员/问题','位置');}

对于我的上传路径,我尝试了一个数字或组合,唯一一个返回 TRUE 值的是 var_dump(is_dir('/wamp/www/quark_edorado/uploads')); 但这也返回了同样的错误.

我不知道我哪里出错了.

更新

我的目录结构是

/application//上市/css/字体/图片/js//系统//上传/

我正在操作 Windows 机器并使用 WAMP.这有什么不同吗?

解决方案

当我尝试通过 $this->load->library('upload', $config); 它不会这样做.

相反,我将配置文件放在 config/upload.php

另一种方法是 $this->upload->initialize($config);

I have been stuck at this point for a long time and even after reading a number of posts, I haven't been able to find a solution.

I am making an interface for a quiz, and in the admin interface, I need to upload images to a folder and upload the image name to the database. I can handle to other things but the image upload is bugging me alot for a long time.

Please take a look at my code below.

The Form

<?php echo form_open_multipart('admin/update_question'); ?>
<?php echo form_hidden('questionid', $question->level); ?>
<?php echo form_label('Comment', 'comment'); ?>
<div class="input">
<?php
    $arr_comment = array(
        'name'  => 'comment',
        'id'    => 'comment',
        'value' => $question->comment
        );
        echo form_textarea($arr_comment);
?>
</div>
<br/>
<?php echo form_label('Answer', 'answer'); ?>
<div class="input">
<?php
    $arr_answer = array(
            'name'  => 'answer',
            'id'    => 'answer',
            'size'  => '10000',
            'value' => $question->answer
    );
    echo form_input($arr_answer);
?>
</div>
<br/>
<?php echo form_label('Image', 'userfile'); ?>
<div class="input">
<?php
    $arr_image = array(
        'name'  => 'userfile',
        'id'  => 'userfile',
        'value' => ''
    );
    echo form_upload($arr_image);
?>
</div>
<br/>
<?php
$arr_button = array(
    'name'  => 'submit',
    'value' => 'Update Question',
    'class' => 'btn primary large'
    );
?>
<div class="input">
<?php echo form_submit($arr_button); ?>
</div>
<br/>
<?php
echo form_close();
if ($error != '')
    echo '<div class="alert-message error">'. $error.' </div>';
echo validation_errors();
?>

I have tried running a js which returns the filename in the upload box, and it does return it.

The Controller

public function update_question() {
        $comment = $this->input->post('comment');
        $answer = $this->input->post('answer');

        echo var_dump(is_dir(base_url().'uploads/'));

        /*
         * Uploading image
         */
        $config['upload_path'] = base_url().'/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_width'] = 0;
        $config['max_height'] = 0;
        $config['max_size'] = 0;
        $config['encrypt_name'] = TRUE;

        $this->load->library('upload', $config);
        if ( ! $this->upload->do_upload())
        {
                $error = array('error' => $this->upload->display_errors());
                print_r($error);
        }
        else
        {
                $arr_image = array('upload_data' => $this->upload->data());
                print_r($arr_image);
        }

        $questionid = $this->input->post('questionid');
        $question_data = array(
            'comment'   => $comment,
            'answer'    => $answer
        );
        $this->load->model('adminmodel', 'admin');
        $question_data = $this->admin->update_question_data($questionid, $question_data);
        //redirect('admin/questions', 'location');
}

For my upload path, I have tried a number or combinations and the only one which returned a TRUE value was var_dump(is_dir('/wamp/www/quark_edorado/uploads')); but this also returned the same error.

I do not know where I am going wrong.

Update

My directory structure is

/application/
/public/
    css/
    fonts/
    images/
    js/
/system/
/uploads/

I am operating a Windows machine and using WAMP. Does that make a difference?

解决方案

I was autoloading the library and somehow when I was trying to initialize the configuration by $this->load->library('upload', $config); it wouldn't do so.

Instead I put my config files in config/upload.php

The other method to do so would have been $this->upload->initialize($config);

这篇关于“上传路径似乎无效".Codeigniter 文件上传不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆