How to bypass file uploading while saving record

Hi does anyone can help me on how to bypass or continue to save record even I don’t select a picture for upload? TIA

Every time I submit to save a record without selecting any picture or file to upload,an error pointing to explode occurs.

You have to use a condtion and check if any file was uploaded, otherwise just skip this part, read the manual:

https://www.php.net/manual/en/control-structures.if.php

Your form processing code needs to detect if a post method form was submitted, then detect any upload errors, before using any of the submitted $_FILES information. You would only reference the uploaded file information if there are no errors.

If the total size of the submitted form data exceeds the post_max_size setting, both the $_FILES and $_POST arrays will be empty, You must detect this condition before going on to test the $_FILES … [‘error’] value.

One of the possible upload errors is - UPLOAD_ERR_NO_FILE (value 4.) If a file upload is ‘required’, you would detect this error and setup a message telling the user that they must upload a file. If the user is not required to upload a file, you would ignore this error. You would only use the rest of the submitted $_FILES information if there is no upload error - UPLOAD_ERR_OK (value 0.)

This code is also filled with unnecessary variables, doesn’t handle filenames with more than one dot, doesn’t validate the extension (a .php file could be uploaded, then used to take over your web site), and should not use md5() for password hashing.

Sponsor our Newsletter | Privacy Policy | Terms of Service