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

[eluser]johansonevR[/eluser]
i have the same problem here , none of the above mentioned solves my problem.
This is my controller. Every time i try to upload a file an error message "You did not select a file to upload" is output. I've tryed this code
Code:
$config['upload_path'] = './images/uploads/';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size']    = '10000';
                $this->load->library('upload', $config);
                $this->upload->do_upload('image');
[/code]
in a test page and it worked.
Code:
<?php
class NewAdv extends Controller{
    function NewAdv(){
        parent::Controller();
        $this->load->model('newAdv_model');
        
    }
    function index(){
        $rules=array(
                   ...
                );
        $this->form_validation->set_rules($rules);
            if($this->form_validation->run()==FALSE){
                $city['city']=$this->session->userdata('city');
                    $this->load->view('newAdv_view',$city);
                
                
                }else{
                    if($this->input->post('expires')==7){
                        $exp=date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+7, date("Y")));
                        }elseif($this->input->post('expires')==14){
                        $exp=date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+14, date("Y")));
                        }
                        //This part here does not work
                $config['upload_path'] = './images/uploads/';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size']    = '10000';
                $this->load->library('upload', $config);
                $this->upload->do_upload('image');
                echo $this->upload->display_errors(); // for debuging
                        $today=date("Y-m-d");
                    $data=array(
                    'title'=>$this->input->post('title'),
                    'adv_body'=>$this->input->post('adv_body'),
                    'price'=>$this->input->post('price'),
                    'currency'=>$this->input->post('currency'),
                    'city'=>$this->session->userdata('city'),
                    'category'=>$this->input->post('category'),
                    'created_by'=>$this->session->userdata('username'),
                    'expires'=>$exp,
                    'created'=>$today
                                );
                    $this->newAdv_model->insert($data);
                        sleep(1);
                        redirect('adv/view/'.mysql_insert_id(),'refresh');
                }                    
    }

}
?>
#12

[eluser]pck76[/eluser]
in my case, I solved the issue by using a relative upload path, so instead of:

Code:
$config['upload_path'] = base_url() . "/blogimg";

I have used:
Code:
$config['upload_path'] = "./blogimg";

and this way it works.
#13

[eluser]RaZoR LeGaCy[/eluser]
I did all the above and got this

$POST returns nothing

Code:
Array
(
    [error] =>

You did not select a file to upload.

    [data] => Array
        (
            [file_name] =>
            [file_type] =>
            [file_path] => ./users/avatars/1/
            [full_path] => ./users/avatars/1/
            [raw_name] =>
            [orig_name] =>
            [file_ext] =>
            [file_size] =>
            [is_image] =>
            [image_width] =>
            [image_height] =>
            [image_type] =>
            [image_size_str] =>
        )

)

Code:
$this->load->library(array('upload'));
            $this->load->helper('file');

            $config['upload_path'] = './users/avatars/'. $id .'/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';
            $config['remove_spaces']  = TRUE;
            $config['overwrite'] = TRUE;

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

            if ( ! $this->upload->do_upload('userfile'))
            {

                $error = array('error' => $this->upload->display_errors(), 'data' => $this->upload->data(),);
            }

Code:
<?php echo form_open_multipart('add_avatar');?>

        <input type="file" name="userfile" size="40" />


        <br /><br />

        <button type="submit" value="true">Upload Avatar</button>

        &lt;/form&gt;
#14

[eluser]searain[/eluser]
It is due to file too big in my case.

But the question is why we didn't generate the right error message.
#15

[eluser]Unknown[/eluser]
i had a similar message while i was trying to upload a zip file.

the issue was that it worked perfectly in firefox, but threw this error in chrome . . . after some reading and testing . . . found out that different browsers have different mime types for zip file.

for chrome the mime type for zip is "application/octet-stream" so modified the application/config/mimes.php file to add 'application/octet-stream' in the array for zip (shown below).

Code:
'zip'    =>  array('application/x-zip','application/octet-stream', 'application/zip', 'application/x-zip-compressed'),

and voilla things just started working.
#16

[eluser]JGarrido[/eluser]
After about 2 hours of research, trial-and-error, and troubleshooting, it turns out I was receiving this very error message for <b>2</b> reasons:

1- The mime type in mimes had to be adjusted for .wav files (see https://github.com/EllisLab/CodeIgniter/issues/537)

2- My application's .htaccess file rewrites the URL to append a trailing slash if it's not present in the requested URL, so a 302 Redirect occurs. When this happens, the uploaded file is lost. What makes this issue a CodeIgniter bug is that the form_open_multipart() helper function seems to ignore the trailing slash of the URL you pass to it (at least as of version 1.7.2), and so I was not able to use it.
#17

[eluser]bennyhill[/eluser]
The trailing slash issue JGarrido mentioned solved my issue. After 4 hours of wasted time!!!
#18

[eluser]Sven Delle[/eluser]
And why would anyone care that you solved your trailing slash problem, if you don't share your solution.

Post your solution to help us other poor bastards who has been struggling with this for close to F I F T E E N hours!!!!




Theme © iAndrew 2016 - Forum software by © MyBB