Proper Way To Display A Default Image When Replacement Image Is Missing in PHP
<p>I have the following code that is used to load user images from a database when their information is displayed.</p>

<p>I was attempting to write it in a way in which it would check if the user already has an image tied to their user id in the database and if so, would leave the image alone and if not, would display a "missing.jpg"/default user image.</p>

<p>I've tried the following, but right now it seems the code is overwriting existing images and replacing them with the missing.jpg image and I don't know why.</p>

<p>I'd appreciate somebody taking a look and showing me why that is.</p>

<pre><code>    //Images
    $thisScript = $_SERVER["SCRIPT_FILENAME"];
    $dirName = dirname($thisScript);
    $relative_path = "images/headshots/".$this-&gt;id.".jpg";
    $missing_path = "images/headshots/missing.jpg";
    $full_path = $dirName . "/" . $relative_path;

    //if(file_exists($relative_path))
    //if(file_exists($_FILES['uploadedfile']['name']))
    if(basename( $_FILES['uploadedfile']['name']) != '' /*and (file_exists($_FILES['uploadedfile']['name']))*/)
    {
            $this-&gt;process_headshot_file($relative_path, $full_path);
    }
    else
    {
        //$this-&gt;process_headshot_file($missing_path, $full_path);
        $query = "UPDATE hraps SET headshot_filename = '".$_SESSION['missing_headshot_image']."' WHERE id = ".$this-&gt;id;
        $result = mydb::cxn()-&gt;query($query);
    }
</code></pre>

<p>Thank you in advance for your help.</p>
