File upload not working (no errors even displayed)

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

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

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

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

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


Code in the controller:
ncs.php:
Code:
function do_upload($id)
    {
        $this->load->model('evidence_upload_model');

        $directory="HTTP://".$_SERVER['SERVER_NAME']."/files/Appl_files/";
        $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());
            print_r($config);
            
            if(!$this->upload->do_upload())
              {
                $error = array('error' => $this->upload->display_errors());

//                return FALSE;
            //    print "not done";
              }
              else
              {
                  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
Thanks

#2
[eluser]bhakti.thakkar[/eluser]
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

Thanks

#3
[eluser]xwero[/eluser]
Good you found it on your own, welcome to the CI world!

#4
[eluser]HrvojeKC[/eluser]
I had the same problem an the fix was to ad these lines into the mimes.php inside the config folder.

Code:
'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';

#5
[eluser]sereyous[/eluser]
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:

Code:
==========
CONTROLLER
==========
  class Homepage extends Controller {
        public function Homepage()
        {
            parent::Controller();
                }
  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
                    $this->upload->initialize($config);
                    
                    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);
                    }

        }
}
====
VIEW
====
/*
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
*/
&lt;?php
    $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.

#6
[eluser]danmontgomery[/eluser]
white page = php error, check apache error log

#7
[eluser]HrvojeKC[/eluser]
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.

#8
[eluser]sereyous[/eluser]
Thanks for the helping out a noob.

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

@HrvojeKC
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.

#9
[eluser]HrvojeKC[/eluser]
Maybe this page will help

http://www.php.net/manual/en/errorfunc.c...ration.php

or simply try
Code:
ini_set('display_errors',1);
error_reporting(E_ALL);

#10
[eluser]sereyous[/eluser]
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!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.