title: saving uploaded files in selected directory
body: <p>I'm building a multiple file uploader, using the  tutorial on this site, <a href="http://techstream.org/Web-Development/PHP/Multiple-File-Upload-with-PHP-and-MySQL" rel="nofollow">http://techstream.org/Web-Development/PHP/Multiple-File-Upload-with-PHP-and-MySQL</a>.  And it works perfectly, however I would like to save the image as a url in SQL rather than just their names, and use the image name as a caption. Here is the code I'm currently using: </p>
  
  <pre><code>if (isset($_POST['add_photos'])) {
  include 'connect.php';
  $album = (isset($_POST['album']) ? $_POST['album'] : null);
  $errors= array();
  foreach($_FILES['photos']['tmp_name'] as $key =&gt; $tmp_name ){
      $file_name = $key.$_FILES['photos']['name'][$key];
      $file_size =$_FILES['photos']['size'][$key];
      $file_tmp =$_FILES['photos']['tmp_name'][$key];
      $file_type=$_FILES['photos']['type'][$key]; 
      if($file_size &gt; 2097152){
          $errors[]='File size must be less than 2 MB';
      }
      include 'connect.php';      
      $stmt = $conn-&gt;prepare("INSERT into album_images(imageURL, AlbumID) VALUES (?, ?)");
      $stmt-&gt;bind_param('ss', $file_name,$album);
      $desired_dir="media/albums";
      if(empty($errors)==true){
          if(is_dir($desired_dir)==false){
              mkdir("$desired_dir", 0700);        // Create directory if it does not exist
          }
          if(is_dir("$desired_dir/".$file_name)==false){
              move_uploaded_file($file_tmp,"user_data/".$file_name);
          }else{                                  //rename the file if another one exist
              $new_dir="media/albums/".$file_name.time();
               rename($file_tmp,$new_dir) ;               
          }
  
         $stmt-&gt;execute();
      $stmt-&gt;close();
      }else{
              print_r($errors);
      }
  }
  if(empty($error)){
      echo "Success";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>HTML code</p>
  
  <pre><code>&lt;form id="add-photos" action="" method="post" enctype="multipart/form-data"&gt;
      &lt;h5&gt;Add Photos&lt;/h5&gt;
      &lt;div class="input-short" id="select_album"&gt;                 
      &lt;?php select_album("SELECT * FROM album"); ?&gt;
      &lt;/div&gt;
      &lt;label class="myLabel" id="upload-images"&gt;
      &lt;input type="file" name="photos[]" id="fileToUpload"  multiple="multiple"/&gt;
      &lt;span&gt;Select Photos&lt;/span&gt;
      &lt;/label&gt; 
      &lt;button  id="facebook-image-submit" type="submit" name="add_photos"&gt;Add Photos&lt;/button&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>This code gives me the following  errors: </p>
  
  <blockquote>
    <p>Warning: mkdir(): No such file or directory in C:\xampp\htdocs\WebDevelopment\AfterGlowWebsite\CMS\functions.php on line: mkdir("$desired_dir", 0700); // Create directory if it does not exist#</p>
  </blockquote>
  
  <p>Files are being added to SQL but not uploaded in the directory.</p>