Welcome Guest, Not a member yet? Register   Sign In
File upload not working (no errors even displayed)

hi all,
i am trying to upload file but it isnt working. below in the code in MVC:
<?php echo form_open_multipart('ncs/do_upload/' . $row->NonConformity_ID, array('id'=>'private_note_form'));?>

        <h4>Upload evidence document(s) </h4>

            &lt;input name="userfile" type="file" id="userfile" /&gt;

            &lt;input type="submit" name="submit" value="Add files" /&gt;  

&lt;?php echo form_close();?&gt;

Code in the controller:
function do_upload($id)

        $config['upload_path'] = $directory;
        $config['max_size']    = '16777215';
        $config['max_width']  = '3000';
        $config['max_height']  = '3000';
        $this->load->library('upload'); // load if it hasn't already been loaded
        $this->upload->initialize($config); // pass the settings to the library
        $data = array('upload_data' => $this->upload->data());
                $error = array('error' => $this->upload->display_errors());

//                return FALSE;
            //    print "not done";
                  print "done";
//                return TRUE;

//        $this->session->set_flashdata('message', 'success in file upload');
//        redirect('ncs/view/' . $id);

No error messages also displayed. files also not uplaoded in the specified path. just a blank page. i have checked the directory access also (CHMOD = 777)

Please help me

At last i found the problem:
i had not specified the allowed type extension as i wanted the user to upload of any file type:
just added this all and things started working

$config['allowed_types'] = 'gif|jpg|png|pdf|txt|doc|docx|xls|ppt|jpeg';

Hope it helps some newbie


Good you found it on your own, welcome to the CI world!

I had the same problem an the fix was to ad these lines into the mimes.php inside the config folder.

'doc'    =>    'application/msword',
'docx'    =>    'application/msword',
'word'    =>    array('application/msword', 'application/octet-stream'),
'xl'    =>    'application/excel',
'xls'    =>    'application/excel',
'xlsx'    =>    'application/excel',
'excell'=>    array('application/msexcell', 'application/octet-stream'),

and inside my controller changed the $config['allowed_types'] to 'word|xls|xlsx|pdf|zip'; before it was 'doc|docx|xls|xlsx|pdf|zip';

I'm having the same issue however setting $config['allowed_types'] did not help. I am autoloading the upload library and my upload folders are all set to 777. When I submit the form nothing happens - just a blank white page. Here's my code:

  class Homepage extends Controller {
        public function Homepage()
  public function index()
            if($this->input->post('message')) {
                // uploads are optional so only do the upload if there is a file to upload
                if(count($_FILES['userfile'])) {
                    // set upload configuration options
                    $config['upload_path'] = 'uploads/'.$this->session->userdata('username').'/images/';
                    $config['allowed_types'] = 'gif|jpg|png|bmp';
                    $config['max_size']  = '2048';
                    $config['overwrite'] = TRUE;
                    $config['remove_spaces'] = TRUE;
                    // initialize upload object variables
                    if(!$this->upload->do_upload()) {
                        $data['error']     = $this->upload->display_errors();
                        $this->load->view('upload_error', $data);
                    } else {
                        $data['upload_data'] = $this->upload->data();
                        $this->load->view('upload_success', $data);

This form shows a thumbnail image if the user has already uploaded one and a button to change the image if desired.
If the change image button is clicked the thumbnail image is faded out with jQuery and the hidden upload box is shown via jQuery
    $thumb   = ($siteinfo->admin_thumb != '')   ? $siteinfo->admin_thumb   : '';
    $message = ($siteinfo->message != '')       ? $siteinfo->message       : '';
    echo $this->tinyMce;
    echo "<h2>Edit Your Homepage</h2>";
    echo form_open_multipart("admin/homepage");
    echo '<div class="form-item">';
    echo '<label class="top">Homepage Image</label>';
    if($thumb != '') {
        echo '<img >session->userdata['username'].'/images/'.$thumb.'" id="image_thumb" /><br />';
        echo form_button(array("name" => "change_image_button", 'id' => "change_image_button", 'content' => "Change Image"));
        echo form_upload(array('name' => 'userfile','id' => 'homepage_image_upload', 'style' => 'display:none'));
    } else {
        echo form_upload("userfile");
    echo '</div>';
    echo '<div class="form-item">';
    echo '<label>Welcome Message</label>';
    echo form_textarea("message", $message);
    echo '</div>';
    echo form_submit("submit", "Update", 'class="submit-button"');
    echo form_close();

This has been driving me nuts. Thanks in advance for any insight.

white page = php error, check apache error log

hi sereyous,
blank white screen points to an php error. Try to enable the display of php errors or to enable them to be logged into a log file so you can track the errors.

Thanks for the helping out a noob.

I did tailf error_log in putty session and attempted an upload - nothing reported.

error_reporting(E_ALL) in index.php. Is this not enough to have PHP display errors? What else do I need to do?

Thanks again.

Maybe this page will help


or simply try

Fixed! I had added a mime type for wmv files in mimes.php and failed to put a comma after the preceding entry.

Why CI did not produce any errors is beyond me, but at any rate, thanks for the help!

Theme © iAndrew 2016 - Forum software by © MyBB