Php上传文件如果无效则设置其他值而不是随机字

This script is working fine.. but i just wonder how do i change the value insert into database if no image selected to value "none" instead of random words like 15199660151398490708

<?php
    $name = ''; $type = ''; $size = ''; $error = '';
    $upload = "asssets/img/";
    $new = time().rand();
    $target =  $upload . $new . basename( $_FILES['photo']['name']);

    require_once('includes/config.php');

    // If form submitted, insert values into the database.
if(isset($_POST['submit']) && !empty($_POST['submit'])) {

        $pic=$new .($_FILES['photo']['name']);

    $query = "INSERT INTO posting(photo) VALUES('$pic')";
        $result = mysql_query($query);
//Writes the photo to the server
if (($_FILES["photo"]["type"] == "image/gif") ||
            ($_FILES["photo"]["type"] == "image/jpeg") ||
            ($_FILES["photo"]["type"] == "image/png") ||
            ($_FILES["photo"]["type"] == "image/pjpeg")) {
            $filename = compress_image($_FILES["photo"]["tmp_name"], $target, 80);
{
        echo "";
        }
    }else
echo "";{
?><form method="post" style="padding:0px;margin:0px;display: block;" enctype="multipart/form-data" autocomplete="off">

<input name="photo" type="file" accept="image/*">
<input name="submit" class="button_post" id="click" type="submit" value=" Post" />

</form><?php } ?>

This is example image mysql phpmyadmin

Check if the file input if empty it's first or an error code is returned because it may be 0 if something went wrong.

if ($_FILES['photo']['size'] == 0 && $_FILES['photo']['error'] == 0)
{
$pic = "none";
}
else
{
$pic = $new .($_FILES['photo']['name']);
}

The code will check if the file input is empty. If empty, it will set the $pic variable value to "none" else it will generate random numbers.

The overall code would then be:

<?php
    $name = ''; $type = ''; $size = ''; $error = '';
    $upload = "asssets/img/";
    $new = time().rand();
    $target =  $upload . $new . basename( $_FILES['photo']['name']);

    require_once('includes/config.php');

    // If form submitted, insert values into the database.
if(isset($_POST['submit']) && !empty($_POST['submit'])) {

           if ($_FILES['photo']['size'] == 0 && $_FILES['photo']['error'] == 0)
{
$pic = "none";
}
else
{
$pic = $new .($_FILES['photo']['name']);
}

    $query = "INSERT INTO posting(photo) VALUES('$pic')";
        $result = mysql_query($query);
//Writes the photo to the server
if (($_FILES["photo"]["type"] == "image/gif") ||
            ($_FILES["photo"]["type"] == "image/jpeg") ||
            ($_FILES["photo"]["type"] == "image/png") ||
            ($_FILES["photo"]["type"] == "image/pjpeg")) {
            $filename = compress_image($_FILES["photo"]["tmp_name"], $target, 80);
{
        echo "";
        }
    }else
echo "";{
?><form method="post" style="padding:0px;margin:0px;display: block;" enctype="multipart/form-data" autocomplete="off">

<input name="photo" type="file" accept="image/*">
<input name="submit" class="button_post" id="click" type="submit" value=" Post" />

</form><?php } ?>