I want to try uploading the image files but that appears is the following message :
“You did not select a file to upload”. Though I have followed the instructions to upload the files in CodeIgniter. What is means of this error message?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
May 18, 2010 7:07am
Subscribe [3]#1 / May 18, 2010 7:07am
I want to try uploading the image files but that appears is the following message :
“You did not select a file to upload”. Though I have followed the instructions to upload the files in CodeIgniter. What is means of this error message?
#2 / May 18, 2010 8:12am
That you did not select a file to upload..(A)
#3 / May 18, 2010 9:54am
That you did not select a file to upload..(A)
Either that or you did not name your fields matching your upload configuration. The input field should be named “userfile”, unless you have set differently in your config array.
#4 / May 18, 2010 11:42pm
I have included a file to be uploaded but still have the message. So what does that mean “userfile” and what should I configure? I have input files in the view and I gave the name “thumbnail”, then I use the command $ this-> upload-> do_upload (‘thumbnail’) inside the controller. But still the error message appears. Is there another solution?
#5 / May 18, 2010 11:53pm
With what you have explained seems to make sense, however without seeing any code it’s hard to say for sure. A neat little thing about CI is
$this->output->enable_profiler(TRUE); //Put in your constructor of your controller or at the beginning of a methodIt will output a lot of info about POST, queries, execution times. Might be helpful why this may be happening. You also haven’t mentioned about your server environment Windows/Linux?. Maybe it’s a folder permissions issue.
#6 / May 19, 2010 4:08am
With what you have explained seems to make sense, however without seeing any code it’s hard to say for sure. A neat little thing about CI is
$this->output->enable_profiler(TRUE); //Put in your constructor of your controller or at the beginning of a methodIt will output a lot of info about POST, queries, execution times. Might be helpful why this may be happening. You also haven’t mentioned about your server environment Windows/Linux?. Maybe it’s a folder permissions issue.
The upload_view code like this :
<?
echo $error;
foreach($asset as $row)
{
$id = $row->id;
$name = $row->name;
$image = $row->image;
echo form_open_multipart('upload/update_upload');
?>
<input type="hidden" name="id" value="<?=$id;?>"/>
<input type="text" name="name" size="20" value="<?=$name;?>"/><br>
<?=base_url();?>public/images/<?=$image;?><br>
<input type="file" name="image"/><br>
<input type="submit" value="Update" name="submit">
<?
}
echo form_close();
?>And the upload controller like this :
function update_upload()
{
$this->load->library('upload');
$config['upload_path'] = './public/images/promo';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '500';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->upload->initialize($config);
$field_name = "image";
$img = $this->input->post('image');
if (!$this->upload->do_upload($field_name))
{
$error=array('error'=>$this->upload->display_errors());
$this->load->view('upload_view',$error);
}
else
{
$data= $this->upload->data();
foreach($data as $value)
{
$name_file = "promo/".$value;
break;
}
$this->upload_model->update($name_file);
redirect('upload/view_upload', 'refresh');
}
}And i use windows for web server.
#7 / May 19, 2010 10:53am
Even though you are on windows, you still to check file permissions. This may not be the issue yet, but for 2000,Server 2k3/8, XP Pro, Vista, & 7 you have to give Full Access on your temporary upload folder. You can usually find this with phpinfo(); which will probably be something like c:\windows\tmp, c:\windows\temp, or c:\wamp\tmp(Wamp Server).
I did notice a few errors in the code. Your foreach loop is before the open form tag, but the form_close tag is after the foreach. In a sense you are opening the form multiple times but only closing it once.
Here is a working example of your code with a few changes (form validation).
//Controller
function index(){
//Set test data
$data['asset'] = (object)array('id'=>'10' , 'name' =>'John Doe', 'image' => 'home-banner.jpg');
$this->load->view('upload_view',$data);
}
function update_upload()
{
$this->load->library(array('upload','form_validation'));
$this->form_validation->set_rules('id', 'id', 'required|trim');
$this->form_validation->set_rules('name','name', 'required|trim');
$config['upload_path'] = './uploads/images';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '500';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->upload->initialize($config);
//Make sure form fields are completed
if($this->form_validation->run() == TRUE){
$img = $this->input->post('image');
//Check if file was uploaded
if (!$this->upload->do_upload('image'))
{
//Test data
$data['asset'] = (object)array('id'=>'10' , 'name' =>'John Doe', 'image' => 'home-banner.jpg');
$data['error'] = $this->upload->display_errors();
$this->load->view('upload_view',$data);
}
else
{
//Uploaded Completed
$data = $this->upload->data();
$name_file = "promo/".$data['file_name'];
$this->upload_model->update($name_file);
redirect('upload/view_upload', 'refresh');
}
}else{
//Test data
$data['asset'] = (object)array('id'=>'10' , 'name' =>'John Doe', 'image' => 'home-banner.jpg');
$this->load->view('upload_view', $data);
}
}
//View
<?
if(isset($error))
echo $error;
echo validation_errors();
$id = $asset->id;
$name = $asset->name;
$image = $asset->image;
echo form_open_multipart('upload/update_upload');
?>
<input type="hidden" name="id" value="<?=$id;?>"/>
<input type="text" name="name" size="20" value="<?=set_value('name',$name);?>"/><br>
<?=base_url();?>uploads/<?=$image;?><br>
<input type="file" name="image"/><br>
<input type="submit" value="Update" name="submit">
<?
echo form_close();
?>I’m not sure if your foreach loop is supposed to be creating a upload form for each asset. If so, it would seem that the way you are redirecting you would only have one image update when someone submits the form.
#8 / May 20, 2010 4:00am
Thank you pickupman…
Finally, i can solve my problem after i read your code.
Thanks 😉