Welcome Guest, Not a member yet? Register   Sign In
How can I check if there's a file selected for upload?
#1

[eluser]Monkeytail[/eluser]
How can I check if there's a file selected for upload?

When I send the form filled with text and an image it all works fine.
Some articles don't need an image.
When I leave the file input field empty.. the system throws an error saying.. there is nothing to upload: and that's correct Smile

The thing I'am after is to add a new article with or without an image.
#2

[eluser]crumpet[/eluser]
Code:
if ($_FILES['image']['size'] > 0){ //theres an image - upload it
#3

[eluser]Thorpe Obazee[/eluser]
You can also check for

Code:
if(isset($_FILES['userfile']['name']))
#4

[eluser]Monkeytail[/eluser]
@ Chamyto, crumpet: thanks!

This did the trick:
Code:
if($_FILES['image']['size'] !== 0 OR empty($_FILES['image']['tmp_name']) == FALSE) {
#5

[eluser]xwero[/eluser]
The right way to do it is
Code:
if($_FILES['image']['error'] == 4)
{
   // no file added to file field
}




Theme © iAndrew 2016 - Forum software by © MyBB