Welcome Guest, Not a member yet? Register   Sign In
Upload has issue with some files "You did not select a file to upload"
#1

[eluser]Diggory Laycock[/eluser]
Hello,

I was wondering if anyone could help me with an issue I'm having with CI's upload class.

I used it in a site last year without any issues. That site only allowed uploading of image files. I'm currently building a site which allows uploading QuickTime .mov files only.

Many files upload correctly, however the occasional file appears to confuse the upload class. It fails validation with the error "You did not select a file to upload" even though the user has.

I've tried spitting out $this->upload->data() and for these problem files it is empty except for the upload paths.

I've tried using Safari on Mac OS X and FireFox on Mac OS X. Both browsers cause the same behaviour in the CI app.

Here's a sample file that causes the issue (sorry it's 17mb):
[removed]

It's most puzzling - does anyone have any ideas?


[edit]

I've reproduced the issue in a test site:
[removed]

below is the code for the upload methods in the test site:

Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
        
        $this->load->library('validation');
        $this->load->helper('form');
        $this->load->helper('number');

    }
    
    function index()
    {
        $data['error'] = '';
        $data['uploadData'] = '';
    
        $this->template->write_view('content', 'upload', $data, TRUE);        
        $this->template->render();
    }




    function processUpload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'mov';        
        $this->load->library('upload', $config);
        
        if ( ! $this->upload->do_upload())
        {
            $data = array('error' => $this->upload->display_errors('<p class="validationError">', '</p>'), 'uploadData' => $this->upload->data());

            $this->template->write_view('content', 'upload', $data, TRUE);        
            $this->template->render();
        }    
        else
        {
            $uploadMetadata = $this->upload->data();

            $data = array(
                            'uploadData'         => $uploadMetadata,
                            'uploadedFileSize'     => byte_format($uploadMetadata['file_size'] * 1024) ,
                        );
            
            $this->template->write_view('content', 'uploadComplete', $data, TRUE);        
            $this->template->render();
        }
    }    


}
#2

[eluser]Diggory Laycock[/eluser]
Ah - I've reduced it even further:

It turns out I was trying to upload a file larger than upload_max_filesize
#3

[eluser]Bramme[/eluser]
So there's something wrong with the errors, hmm. Maybe an if statement that's wrong somewhere.
#4

[eluser]Diggory Laycock[/eluser]
After a bit of reading the PHP docs I noticed this:
http://uk2.php.net/manual/en/features.fi....php#73762
Quote:if POST size exceeds server limit then $_POST and $_FILES arrays become empty. You can track this using $_SERVER['CONTENT_LENGTH'].
For example:

Code:
&lt;?php
$POST_MAX_SIZE = ini_get('post_max_size');
$mul = substr($POST_MAX_SIZE, -1);
$mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)));
if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) $error = true;
?&gt;

So it's not CI missing an error - PHP fails silently, unless the upload form has an accurate hidden input before the file input e.g.
Code:
&lt;input type="hidden" name="max_file_size" value="1000" /&gt;
#5

[eluser]Diggory Laycock[/eluser]
I also should have set the file upload class's max_size preference - then it would have reported the error correctly.

My fault really.
#6

[eluser]Unknown[/eluser]
i've got the same problem here. I use extjs as frontend and CI for the backend. first time, i always get this error message. and then i change my code, and it works.

below is my extjs code, i use Ext.ux.UploadDialog extension :

Code:
dialog = new Ext.ux.UploadDialog.Dialog({
        url: '/simbada/index.php/kiba/upload',
    baseParams: {id: action.result.id},
    reset_on_hide: false,
    allow_close_on_upload: false,
    upload_autostart: false,
    method: 'POST'
});
dialog.show();

and this is my controller :
Code:
function upload()
{
    $config['upload_path'] = './uploads/images/';
        $config['allowed_types'] = 'gif|jpg|png|bmp';
        $config['max_size'] = '10000';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';
            
    $index = $this->session->userdata('indexgbr');
        $this->load->library('upload', $config);
                        
    if ( ! $this->upload->do_upload('file'))
        {
            echo("{errors: {id:'name', msg:'" . $this->upload->display_errors() . "'}}");
        return;
        }    
        else
        {
            $errUpload = "";
            $uploadData = $this->upload->data();
            $path = $uploadData['file_name'];
    }
            
    if($index == 1)
    {
        $affectedRows = $this->kiba_model->addGambar($this->input->post('id'),$path,'',true);
    }
    else
    {
        $affectedRows = $this->kiba_model->addGambar($this->input->post('id'),$path,'',false);
    }
            
    echo('{success: true}');
}

if i upload some files, the uploaded files was copied into the server, but the do_upload() method still return false and display_errors() method always return "You did not select a file to upload".
Anyone know how to solve this problem? I tried to use a simple html form to upload the file and it's success. Please help me.
#7

[eluser]prato[/eluser]
Hey, there!

just a comment. The error message "You did not select a file to upload" occurs when you didn't set the field name of your image

like

Code:
$this->upload->do_upload();

the correct code is

Code:
$this->upload->do_upload("field_name");
#8

[eluser]Unknown[/eluser]
[quote author="Diggory Laycock" date="1224871266"]After a bit of reading the PHP docs I noticed this:
http://uk2.php.net/manual/en/features.fi....php#73762
Quote:if POST size exceeds server limit then $_POST and $_FILES arrays become empty. You can track this using $_SERVER['CONTENT_LENGTH'].
For example:
[/quote]

Settting higher post_max_size (and, of course, upload_max_filesize) value helps me in the same problem.

Diggory Laycock, thanks.
#9

[eluser]Unknown[/eluser]
I had the same issue and it could be the file is too big or that you are using form_open() that doen't show enctype="multipart/form-data" instead use form_open_multipart()
#10

[eluser]Unknown[/eluser]
[quote author="prato" date="1255573147"]Hey, there!

just a comment. The error message "You did not select a file to upload" occurs when you didn't set the field name of your image

like

Code:
$this->upload->do_upload();

the correct code is

Code:
$this->upload->do_upload("field_name");
[/quote]

I solve the same problem with this answer,thanks.




Theme © iAndrew 2016 - Forum software by © MyBB