0

i have problem when upload images in codeigniter, So i have controller that upload images like this :-

 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));
}

and view is like this :-

<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>

when i upload thee images in my site the error is display like :-

Severity: Notice

Message: Undefined index: inputUpProfile

Filename: controllers/home.php

Line Number: 47

and

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: eventpic

Filename: controllers/home.php

Line Number: 74

and

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at D:\AppServ\www\sys\system\core\Exceptions.php:185)

Filename: core/Common.php

Line Number: 442

so where are the problem in my code.

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

edit :-

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" ) ) 

i need from this array [file_name] to save in DB, how can i read this.

1 Answer 1

1
  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();
    }
Sign up to request clarification or add additional context in comments.

1 Comment

[upload_data][file_name] this will give you file name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.