我的图像没有上传到我的本地wamp服务器中的codeigniter中的特定目录,其显示目录不正确错误

时间:2022-09-03 21:21:46

I have spent days trying to make this work based on the examples in the documentation but I am missing something

我花了几天时间尝试根据文档中的示例来完成这项工作,但我遗漏了一些东西

I have a simple image upload form on my local server where users can upload image and it need to store in local folder but It not work . I am also take a permission to my folder is 777 but still its taking problem what I can do that. My Image is not upload to the specific directory in codeigniter in my Local wamp server its display directory is not correct error.

我在我的本地服务器上有一个简单的图像上传表单,用户可以上传图像,它需要存储在本地文件夹中,但它不起作用。我也获得了对我的文件夹的许可是777,但仍然是它的问题我能做什么。我的图像没有上传到我的本地wamp服务器中的codeigniter中的特定目录,其显示目录不正确错误。

MY Controller Code is given below

我的控制器代码如下

public function do_upload()
 { 
    $upPath= './uploads/';
    if(!file_exists($upPath)) 
    {
        mkdir($upPath, 0777, true);
    }
    $config = array(
     'upload_path' => $upPath,
     'allowed_types' => "gif|jpg|png|jpeg",
    'overwrite' => TRUE,
    );

    $this->load->library('upload', $config);

    if(!$this->upload->do_upload('userfile'))
    { 
        $data['imageError'] =  $this->upload->display_errors();
        print_r($data['imageError']);
    }
    else
    {
        $imageDetailArray = $this->upload->data();
        return $imageDetailArray['file_name'];
    }
}

public function add_article(){

    if($this->session->userdata('writer_logged_in')){

        if ($this->form_validation->run() === FALSE)
            {

                $data['main_content']="writer/profile";
                $this->load->view('include/template',$data);


            }
        else
            {
                $image = $this->do_upload();
                echo $image;
                die();
                $result=$this->writer_model->new_article();
                if($result==1){
                    $this->session->set_flashdata('article_insertion',"Article has been successfully added.");
                    redirect('writer/profile');
                }
            }

    }
    else{
        redirect('site');
    }
}

My View Code is given below

我的观察代码如下

<form method="post" action="<?php echo base_url(); ?>writer/add_article" enctype="multipart/form-data">
        <?php echo validation_errors(); ?>
        <div class="form-group">
            <label for="title">Title</label>
            <input type="text" name="title" id="title" placeholder="Article title" value="<?php echo set_value('title'); ?>" class="form-control" />
        </div>
        <div class="form-group">
            <label>Image</label>
            <input type="file" id="image"  name="userfile" class="form-control" value="<?php echo set_value('userfile'); ?>"/>
        </div>

        <div class="form-group">
            <label for="body">Article detail</label>
            <textarea name="body" id="body" class="form-control" rows="10" cols="40"  placeholder="Provide Articles content. Basic HTML is allowed."><?php echo set_value('body'); ?></textarea>
        </div>

        <button type="submit" class="btn btn-primary">Submit</button>

2 个解决方案

#1


0  

Now My Error is Resolved I have just clear my temp caches and now my image is upload to the specific folder . Thanks For you cooperation and Answers. Now I am Continued my work.......!

现在我的错误已解决我刚刚清除了我的临时缓存,现在我的图像上传到特定文件夹。谢谢你的合作和答案。现在我继续我的工作.......!

#2


0  

I recommend this code:

我推荐这段代码:

$upPath = './uploads/';
if(!file_exists($upPath)) 
{
    mkdir($upPath, 0777, true);
}
$config['upload_path'] = $upPath;
$config['allowed_types'] = 'gif|jpg|png';

$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('userFile')){
    $fileData = $this->upload->data();
    $uploadData[$i]['file_name'] = $fileData['file_name'];
    $uploadData[$i]['created'] = date("Y-m-d H:i:s");
    $uploadData[$i]['modified'] = date("Y-m-d H:i:s");
} 

for more details please read the CodeIgniter manual

有关详细信息,请阅读CodeIgniter手册

#1


0  

Now My Error is Resolved I have just clear my temp caches and now my image is upload to the specific folder . Thanks For you cooperation and Answers. Now I am Continued my work.......!

现在我的错误已解决我刚刚清除了我的临时缓存,现在我的图像上传到特定文件夹。谢谢你的合作和答案。现在我继续我的工作.......!

#2


0  

I recommend this code:

我推荐这段代码:

$upPath = './uploads/';
if(!file_exists($upPath)) 
{
    mkdir($upPath, 0777, true);
}
$config['upload_path'] = $upPath;
$config['allowed_types'] = 'gif|jpg|png';

$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload('userFile')){
    $fileData = $this->upload->data();
    $uploadData[$i]['file_name'] = $fileData['file_name'];
    $uploadData[$i]['created'] = date("Y-m-d H:i:s");
    $uploadData[$i]['modified'] = date("Y-m-d H:i:s");
} 

for more details please read the CodeIgniter manual

有关详细信息,请阅读CodeIgniter手册