简体   繁体   中英

checking if image is NULL or empty in php

I need to check if the image is NULL on my webpage. Currently i'm only been able to upload .png files on my website.

<img src="uploads/user_pic/<?php echo $first_name.'_'.$last_name.'/'.'profile_pic'.'/'.'profile_pic.'.'png'; ?>" class="img-thumbnail" />

so, I've been trying to do this, but I've run out of idea's on how to check on missing item's.

switch (missingImage) {
 case "jpg":
    <img src="uploads/user_pic/<?php echo $first_name.'_'.$last_name.'/'.'profile_pic'.'/'.'profile_pic.'.'jpg'; ?>" class="img-thumbnail" />
    break;
 ... so on and so forth
 }  

Do something like this:

$photoName = $_FILES["photo"]["name"];

Then you check if it is empty:

if(empty($photoName))
{
    echo json_ecode(array("message" => "photo required"));
}

We check for size and if there are any errors. Replace imageName with how your image field is called.

if ($_FILES['imageName']['size'] == 0 && $_FILES['imageName']['error'] == 0){
  //File is empty

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM