Welcome Guest, Not a member yet? Register   Sign In
How do I make a File Upload non Mandatory

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?

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;


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.

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.


Theme © iAndrew 2016 - Forum software by © MyBB