PHP upload image replication
<p>I am using AgileUploader with PHP to allow users to upload images. My script checks if a folder exists, if not creates the folder based on the users session id. From there it allows user to upload a single file which duplicate this file to 3 different sizes.</p>

<p>Everything works great for 99.8% of the time however, twice now (out of thousands), I have had an upload folder replicate the root images folder. My folder structure is:</p>

<pre><code>temp/images/sessionid/large
temp/images/sessionid/medium
temp/images/sessionid/thumbnails
</code></pre>

<p>The issue sometimes creates:</p>

<pre><code>temp/images/sessionid/sessionid/sessionid/ALL OTHER FOLDERS IN temp/images/
</code></pre>

<p>I thought it may be a session issue but the folder is being created with a valid session id.</p>

<p>I am running 3 webservers all sync'ing to each other and the replication issue is causing some delay in valid images to be sync'ed because its replicating EVERY folder and file in the root temp/images.</p>

<p>I then thought it might be an issue with my resizer dropping the path:</p>

<pre><code>$listing_image = glob($temp_main_folder . "/large/*.{jpg,gif,png}", GLOB_BRACE);
if(count($listing_image) &lt; 7){
    if(move_uploaded_file($tmp_name, "$temp_main_folder/large/$name")){
        $resizeObj = new resize("$temp_main_folder/large/$name"); 
        $resizeObj -&gt; resizeImage(350, 350, 'auto');
        $resizeObj -&gt; saveImage("$temp_main_folder/medium/$name", 90);
        $resizeObj -&gt; resizeImage(120, 120, 'auto');
        $resizeObj -&gt; saveImage("$temp_main_folder/thumbnails/$name", 90);
    }
}
</code></pre>

<p>Anyway, like I said, it works 99.8% so I dont think its an issue with any of the code...but then again, it has failed twice.</p>

<p>My question is, is there a way for PHP to restrict the folder size when using mkdir or limiting the number of subfolders and file? Or any suggestions about some other validation techniques when it comes to uploading files.</p>

<p>Each folder will always have 3 subfolders, each subfolder will have a max of 6 files, each file will be a maximum of 1mb in size.</p>
