Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Codeigniter中上载图像_Php_Codeigniter - Fatal编程技术网

Php 如何在Codeigniter中上载图像

Php 如何在Codeigniter中上载图像,php,codeigniter,Php,Codeigniter,我在codeigniter中上载图像时遇到问题,因此我有一个控制器,可以像这样上载图像:- public function index() { $this->load->model('blog'); $type = "text"; if (isset($_POST['post'])) { if (isset($_POST['type']) && $_POST['type'] == "image") {

我在codeigniter中上载图像时遇到问题,因此我有一个控制器,可以像这样上载图像:-

 public function index()
{
    $this->load->model('blog');
    $type = "text";
    if (isset($_POST['post'])) {
        if (isset($_POST['type']) && $_POST['type'] == "image") {
            $type = "image";
        }
        if (strlen($_FILES['inputUpProfile']['name']) > 0) {
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '2048';
            $config['encrypt_name'] = true;
            $this->load->library('upload', $config);
            if (!$this->upload->do_upload('inputUpProfile')) {
                $error = $this->upload->display_errors();
                if (is_array($error)) {
                    foreach ($error as $er) {
                        $this->errors[] = $er;
                    }
                } else {
                    $this->errors[] = $error;
                }
            } else {
                $updata = $this->upload->data();
                $imagePath = './uploads/' . $eventpic;
                if (file_exists($imagePath)) {
                    @unlink($imagePath);
                }
                $eventpic = $updata['raw_name'] . $updata['file_ext'];
            }
        }
        $result = $this->blog->addPost($_SESSION['user_id'], $type, $this->input->post('post'), $eventpic);
    }

    $result = $this->blog->getPosts($_SESSION['user_id'], 0, 10);
    $this->template->build("home_view", array("response" => $result));
}
<div class="textstatus">
    <input id="inputUpProfile" name="inputUpProfile"
           class="inputUpProfile hidefile" type="file"/>
    <input type="button" id="PicUpProfile" class="sentpic" value="addpic">
    <input name="post" type="text" id="text" placeholder="message ...">
    <input type="submit" id="sent" value="Send">
</div>
</form>
</div>
观点是这样的:-

 public function index()
{
    $this->load->model('blog');
    $type = "text";
    if (isset($_POST['post'])) {
        if (isset($_POST['type']) && $_POST['type'] == "image") {
            $type = "image";
        }
        if (strlen($_FILES['inputUpProfile']['name']) > 0) {
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '2048';
            $config['encrypt_name'] = true;
            $this->load->library('upload', $config);
            if (!$this->upload->do_upload('inputUpProfile')) {
                $error = $this->upload->display_errors();
                if (is_array($error)) {
                    foreach ($error as $er) {
                        $this->errors[] = $er;
                    }
                } else {
                    $this->errors[] = $error;
                }
            } else {
                $updata = $this->upload->data();
                $imagePath = './uploads/' . $eventpic;
                if (file_exists($imagePath)) {
                    @unlink($imagePath);
                }
                $eventpic = $updata['raw_name'] . $updata['file_ext'];
            }
        }
        $result = $this->blog->addPost($_SESSION['user_id'], $type, $this->input->post('post'), $eventpic);
    }

    $result = $this->blog->getPosts($_SESSION['user_id'], 0, 10);
    $this->template->build("home_view", array("response" => $result));
}
<div class="textstatus">
    <input id="inputUpProfile" name="inputUpProfile"
           class="inputUpProfile hidefile" type="file"/>
    <input type="button" id="PicUpProfile" class="sentpic" value="addpic">
    <input name="post" type="text" id="text" placeholder="message ...">
    <input type="submit" id="sent" value="Send">
</div>
</form>
</div>

那么我的代码中的问题在哪里呢

/***************

编辑:-

Array ( [upload_data] => Array ( [file_name] => 67429_133961013479569_306349156_n3.jpg [file_type] => image/jpeg [file_path] => D:/AppServ/www/d5n/rashaqa2/uploads/ [full_path] => D:/AppServ/www/d5n/rashaqa2/uploads/67429_133961013479569_306349156_n3.jpg [raw_name] => 67429_133961013479569_306349156_n3 [orig_name] => 67429_133961013479569_306349156_n.jpg [client_name] => 67429_133961013479569_306349156_n.jpg [file_ext] => .jpg [file_size] => 34.05 [is_image] => 1 [image_width] => 720 [image_height] => 540 [image_type] => jpeg [image_size_str] => width="720" height="540" ) ) 

我需要从这个数组
[file\u name]
保存到数据库中,我如何读取它。

[upload\u data][file\u name]这将为您提供文件名
  if($_FILES['nameofinputtype']['error'] == UPLOAD_ERR_OK)
    {
       // A file was uploaded

            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';

            $this->load->library('upload', $config);
            $imagen = $this->upload->do_upload();
    }
  if($_FILES['nameofinputtype']['error'] == UPLOAD_ERR_OK)
    {
       // A file was uploaded

            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';

            $this->load->library('upload', $config);
            $imagen = $this->upload->do_upload();
    }