How do I make a File Upload non Mandatory

#1
[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?

#2
[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;

}
...

#3
[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.

#4
[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/


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.