Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter do_upload() silently fails on "success"

I'm using CodeIgniter to write an image upload form. I've previously got similar code to work for a different site. At the moment - the code for receiving a multipart/form-data image is failing silently. While configuring the server/script I received errors, such as incorrect filepath, dissalowed mime-types, but now I get nothing.

The code below returns: "ABC" and fails before "D" without error.

If I change 'photo_filedata' to 'photo_filedata2' I get a more useful error: "ABCD You did not select a file to upload."

I am at a complete loss to debugging this, since I'm getting no error at all from the server.

Does anyone know what might be happening?

Server: WAMP, running on Windows 7. Have an existing project that does file uploads with no problem.

function upload_photo()
{
    echo "A";

    $config['upload_path'] = './images/uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['file_name'] = 'photo_' . substr(md5(time()), 0, 16);
    $config['max_size']    = 2000;
    $config['max_width']  = 0;
    $config['max_height']  = 0;

    echo "B";

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

    echo "C";

    $result = $this->upload->do_upload('photo_filedata');

    echo "D";

    if (!$result)
    {
        $error = $this->upload->display_errors();
        $data = false;
    }   
    else
    {
        $error = false;
        $data = $this->upload->data();
    }

    $this->load->view('home-photo-upload', array('error' => $error, 'data' => $data));
}
like image 214
John Beech Avatar asked Jun 22 '11 04:06

John Beech


1 Answers

$config['upload_path'] = 'uploads/category/'.$id.'/';
        //echo $file_name;die;
        //echo $config['upload_path'];
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size'] = '750';
        $config['max_width'] = '1920';
        $config['max_height'] = '1280';
        $this->load->library('upload');
         foreach ($_FILES as $key => $value) {
            //print_r($key);

            if (!empty($key['name'])) {

                $this->upload->initialize($config);
                if (!$this->upload->do_upload($key)) {
                  // echo 'test';die;
//                    rmdir('uploads/category/'.$id);
                    $errors = $this->upload->display_errors();
                    flashMsg($errors);
                }
}
}

try this!

like image 176
srbhbarot Avatar answered Oct 04 '22 02:10

srbhbarot