如何检查用户是否上传了图像,如果没有显示默认图像?

I have a upload function implemented in my html code. In the following I'm saving the user input (image-upload) as an array in my SQL database:

if(isset($button_pressed))
{
    $image = $_FILES['image']['name'];
    move_uploaded_file($_FILES['image']['tmp_name'], 'images/' . $_FILES['image']['name']);
    ....
}

Now I have a problem. In case when somebody doesn't upload a image, I want that a default image (no_img.png) will be displayed instead of nothing. For example, now the user upload images were shown but if a user doesn't upload a picture I want a default image output.

Does anybody know how to do that?

It should work like this:

if (/*no image uploaded*/) {
    //set default image;
} else {
    //set user uploaded image; 
}

Thank you!

Due to the fact that the move_uploaded_file function returns a boolean based on whether or not the file you passed to it was actually uploaded and moved, you can do it in a very short method as follows:

if(move_uploaded_file($_FILES['image']['tmp_name'], 'images/' . $_FILES['image']['name'])) {
  // Show uploaded image (HTML to draw the uploaded image by its path)
} else {
  // Show default image (HTML to draw the default image by its path)
}

This code will show the uploaded image both if the image was uploaded and once it's been moved, and if it wasn't uploaded it'll show the default

As excerpted from the PHP documentation:

If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

Thanks