Welcome Guest, Not a member yet? Register   Sign In
Optional validated upload box.
#1

[eluser]Unknown[/eluser]
Hi all,

I want to have a optional upload box, which validates if the user have uploaded and displays an error message. How can I check a file has been selected before running do_upload?

Thanks.
#2

[eluser]pickupman[/eluser]
You will need to use js validation. Check if field name exists before enabling submit button. Otherwise all processing is done on server side.
#3

[eluser]Unknown[/eluser]
Ok, cheers Smile
#4

[eluser]danmontgomery[/eluser]
JS validation is pretty, but it shouldn't be relied on. You still always want server side validation, and you just need to check the $_FILES array.

Code:
if($_FILES['field_name']['name']) {
    // File was uploaded
} else {
    // File was not
}




Theme © iAndrew 2016 - Forum software by © MyBB