CodeIgniter Forums
Uploading a file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Uploading a file (/showthread.php?tid=16827)



Uploading a file - El Forum - 03-17-2009

[eluser]Unknown[/eluser]
Hi Everyone,

Could you please help me with this?

I'm using the file uploading class to upload a file:
http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

However, it tries to upload a file even if I don't actually choose anything. This is particularly annoying when I'm trying to update a form which has the option to update an image.

If I'm using the following input in my form,

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

How do I check if a file has actually been chosen or not? I've tried the following statement and it does not work.

$filename = $this->input->post('userfile');


Uploading a file - El Forum - 03-17-2009

[eluser]eoinmcg[/eluser]
Hi,

Uploads are stored in $_FILES rather $_POST, hence not showing up in $this->input->post('fieldname')

Try
Code:
if($_FILES)
  {
    // manage uploaded file(s) here
  }
else
  {
    // no files uploaded
  }

There may be a better way of doing it, though this works for me...


Uploading a file - El Forum - 03-18-2009

[eluser]spagi[/eluser]
Code:
if (isset($_FILES['userfile']))
{

some code
}
else {
some code
}