php directory read and delete existing files
<p>I am trying to make sure that when the user uploads a profile picture, there can only be one image within the dir "profile_pic". I am openning and reading the dir with a while loop but the @unlink is not working. Below is the php code:</p>

<pre><code>        $directory = "uploads\\".$id."\images\profile_pic\\";
        if (glob($directory . "*.jpg") != false) {
            $filecount = count(glob($directory . "*.jpg"));
            if ($filecount &gt; 0) {
                //delete exiting pics in folder profile_pic
                $handle = opendir($directory);
                while ($handle &amp;&amp; ($file = readdir($handle)) !== false) {
                    if ( unlink($entry)) {
                    $msg .= "File Deleted";
                    }
                }
                closedir($directory);
            }
        }
</code></pre>
