Getting PHP (Valums File Uploader) script to NOT overwrite if file exists
<p>/----FIXED THE ISSUE----/</p>

<p>I'm creating a site where you can upload a zip file and we will extract it and provide a method of viewing your html site before viewing it. I can see my main problem is going to be bandwidth right now and that is due to the fact that once you access the <a href="https://github.com/valums/file-uploader" rel="nofollow">Valums File-Uploader</a> on our page you can upload infinite files.</p>

<p>I've already changed the script so that it opens a session and grabs the persons username and no matter what they upload it goes in the format of:</p>

<pre><code>        if ($this-&gt;file-&gt;save($uploadDirectory . $_SESSION['myusername'] . '.site.' . $ext)){
</code></pre>

<p>This makes it so no matter what they upload it gets created in the format of username.site.zip.</p>

<p>I think I need to recode this section, but am not 100% what to change it to - I have tried everything I could think of with no avail:</p>

<pre><code>if(!$replaceOldFile){
        /// don't overwrite previous files that were uploaded
        while (file_exists($uploadDirectory . '.' . $_SESSION['myusername'] . '.site.' . $ext)) {
            return array('error'=&gt; 'Could not save uploaded file.' .
            'The upload was cancelled, or server error encountered');
        }
    }
</code></pre>

<p>Please help me out on this!</p>

<p>/----THE FIX----/</p>

<pre><code>while (file_exists($uploadDirectory . '.' . $_SESSION['myusername'] . '.site.' . $ext)) {
</code></pre>

<p>Needed to be:</p>

<pre><code>while (file_exists($uploadDirectory . '' . $_SESSION['myusername'] . '.site.' . $ext)) {
</code></pre>

<p>The directory path was ending in / and then being followed by .username.site.zip</p>

<p>Removed the . from the beginning of the file and it now works.</p>
