• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter 3 File Upload Issue

#1
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
Reply

#2
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();

Reply

#3
Also you can check your browsers development tools and see what is going on for errors F12 key on most.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

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

Don't know why !! Sad
Reply

#5
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.
On the package it said needs Windows 7 or better. So I installed Linux.
Reply

#6
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
Reply

#7
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.
Reply

#8
managed other ways. thanks
Reply

#9
(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
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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