CodeIgniter Forums
Codeigniter 3 File Upload Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Codeigniter 3 File Upload Issue (/showthread.php?tid=68344)



Codeigniter 3 File Upload Issue - codeigniterd - 06-26-2017

View File
Code:
<form id="DocUploadForm" action="" method="post" enctype="multipart/form-data">
                                        <div class="box-body">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="pdocupload">Upload Document</label>
                                                    <input type="file" id="pdocupload" name="pdocupload">
                                                    <p class="help-block">Example .pdf,.jpg,.doc, .docx files</p>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                            </div>
                                            <div class="clearfix"></div>
                                            <div class="box-footer">
                                                <input id="UserId" name="UserId" type="hidden" value="">
                                                <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" >
                                                <button id="pdu_cancel" name="pdu_cancel" type="button" onclick="pduCancelFunc();" class="btn btn-default">Cancel</button>
                                                <button id="pdu_submit" name="pdu_submit" type="button" onclick="pduUploadFunc();" class="btn btn-info">Upload</button>
                                            </div>
                                        </div>
                                    </form>

JS File *i am using jquery validate to validate the form
Code:
$("#DocUploadForm").validate({
                rules: {
                    pdocupload: {
                        required: true
                    }
                },
                messages: {
                    pdocupload: {
                        required: "Choose some files first"
                    }
                },
                submitHandler: function(form) {
                    //$.LoadingOverlay('show');
                    var dataString = $(form).serialize();
                    $.ajax({
                        url: "<?php echo site_url('mycontroller/DocUploadFormSubmit'); ?>",
                        type: "POST",
                        cache: false,
                        data: dataString,
                        success: function(response) {
                            alert(response);
                        }            
                    });
                    return false;
                }
            });
       });
        
function pduUploadFunc()
{
    $("#DocUploadForm").submit();
}
Controller
Code:
$config['upload_path']          = './assets/';
$config['allowed_types']        = 'gif|jpg|png|pdf|doc|docs';
$config['max_size']             = 8048;
//$config['max_width']            = 0;
//$config['max_height']           = 0;

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

$claenUserId = $this->security->xss_clean($this->input->post('UserId'));

if($this->upload->do_upload('pdocupload'))
{
   echo "file upload success";
}
else
{
   echo "file upload failed";
}

I is always showing "file uoload failed". There is no permission issues. i have checked. Dont know the reason !! Thanks in advance for help. Smile


RE: Codeigniter 3 File Upload Issue - Martin7483 - 06-27-2017

Use this and see what is causing the problem

PHP Code:
$this->upload->display_errors() 

This will get the error messages that where set by CI during upload

PHP Code:
if($this->upload->do_upload('pdocupload'))
{
 
  echo "file upload success";
}
else
{
 
  echo "file upload failed";
 
  echo $this->upload->display_errors();




RE: Codeigniter 3 File Upload Issue - InsiteFX - 06-27-2017

Also you can check your browsers development tools and see what is going on for errors F12 key on most.


RE: Codeigniter 3 File Upload Issue - codeigniterd - 06-27-2017

it is showing
Code:
<p>You did not select a file to upload.</p>

Don't know why !! Sad


RE: Codeigniter 3 File Upload Issue - rtenny - 06-28-2017

Just a few things I would check.
Is the file of the allowed type? (I had jpg files called file.jpeg which caused an error)
if $config['allowed_types'] case insensitive? What would happen if the file is called file.JPG
Is the file upload limit in php.ini high enough? You set it in the config to 8048 but if in php.ini its still to 2M this will still fail
Is max_post_size in php.ini high enough?

I hope this helps.


RE: Codeigniter 3 File Upload Issue - codeigniterd - 06-28-2017

All Things I have Checked many times and those are fine.. My Issue is file is not uploading i guess. $_FILES has nothing..
Don't know why !! Confused Confused Confused


RE: Codeigniter 3 File Upload Issue - PaulD - 06-28-2017

Try removing the jquery validation from the form. It might be that the serialisation is stopping the form upload from working as a multi type form. Can you do a form upload test page without any js and see if you can upload a form then. If you can, the problem is the js. If you can't then at least you are starting to work out where the problem might be.


RE: Codeigniter 3 File Upload Issue - codeigniterd - 07-03-2017

managed other ways. thanks


RE: Codeigniter 3 File Upload Issue - 700brains - 10-08-2017

(07-03-2017, 08:00 PM)codeigniterd Wrote: managed other ways. thanks

Hi please which other ways do you use in making it work because mine is not working. Thanks