CodeIgniter Forums
How do I make a File Upload non Mandatory - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: How do I make a File Upload non Mandatory (/thread-32912.html)



How do I make a File Upload non Mandatory - El Forum - 08-09-2010

[eluser]Namsu[/eluser]
I have my file field mixed with other form data, so I want to know how I can restrict the Upload library from throwing an error when it doesn't see a file?


How do I make a File Upload non Mandatory - El Forum - 08-09-2010

[eluser]Namsu[/eluser]
I didn't find anything within the class that allows you to do that. I just added an additional parameter on the 'do_upload()' method called $mandatory. Default is 1 which means they are mandatory, and a supplied 0 means not mandatory. So I did the following:

function do_upload($field = 'userfile', $mandatory = 1)

{

if ($mandatory == 0 && $_FILES[$field]['tmp_name'] == "")

{

return TRUE;

}
...


How do I make a File Upload non Mandatory - El Forum - 08-09-2010

[eluser]jsfmills[/eluser]
On a Microsoft platform utilizing IIS,you may run into a situation where, upon moving the uploaded file.PHP also supports PUT-method file uploads as used by Netscape Composer and clients.If the upload was too large,didn't work out well,etc.then PHP will fill in the error variable appropriately.


How do I make a File Upload non Mandatory - El Forum - 08-15-2010

[eluser]Namsu[/eluser]
This is probably a better solution. I did not see this before and probably should have searched properly. Some similar ways but an extra line which I didn't add caused my code not to work.

http://ellislab.com/forums/viewthread/161178/