Add a new folder when uploading files using php
<p>I want to automatically create a folder, using the users email address, if one does not already exists. This action should occur when they upload a file. </p>

<p>SOLVED. I updated this code for anyone who might need it. Thanks!</p>

<p>Here is my code: </p>

<pre><code>if(isset($_POST["checkFile"]) &amp;&amp; $_FILES["selectFile"]["name"] != "") {
            $target_path_pdf = "uploads/pdfs/$email/";

            if ( ! is_dir($target_path_pdf)) {
                mkdir($target_path_pdf);
            }

            $target_path_pdf = $target_path_pdf . str_replace(' ', '_', basename($_FILES["selectFile"]["name"]));
            if(move_uploaded_file($_FILES["selectFile"]["tmp_name"], $target_path_pdf)) {
            }
            else {
                $flag = 1;
            }
            $pdfcaption = $_POST['pdfCaption1'];
        }

        if(isset($_POST["checkPicture"]) &amp;&amp; $_FILES["selectPicture"]["name"] != "") {
            $target_path_pic = "uploads/pictures/$email/";

            if ( ! is_dir($target_path_pic)) {
                mkdir($target_path_pic);
            }


            $target_path_pic = $target_path_pic . str_replace(' ', '_', basename($_FILES["selectPicture"]["name"]));
            if(move_uploaded_file($_FILES["selectPicture"]["tmp_name"], $target_path_pic)) {
            }
            else {
                $flag = 1;
            }
            $piccaption = $_POST['picCaption1'];
        }
</code></pre>
