title: file uploading and creating upload folders with Codeigniter
body: <p>I'm having this function inside my Album_Model: </p>
  
  <pre><code>public function upload($album_id, $album){
          $album= strtolower($album);
  
          $upload_config = array(
              'upload_path'   =&gt;  './uploads/'.$album,
              'allowed_types' =&gt;  'jpg|jpeg|gif|png',
              'max_size'      =&gt;  '2000',
              'max_width'     =&gt;  '680',
              'max_height'    =&gt;  '435', 
          );
  
          $this-&gt;load-&gt;library('upload', $upload_config);
  
          // create an album if not already exist in uploads dir
  // wouldn't make more sence if this part is done if there are no errors and right before the upload ??
          if (!is_dir('uploads')) {
              mkdir('./uploads', 0777, true);
          }
          if (!is_dir('uploads/'.$album)) {
              mkdir('./uploads/'.$album, 0777, true);
          }
  
          if (!$this-&gt;upload-&gt;do_upload('imgfile')) { 
              // upload failed
              return array('error' =&gt; $this-&gt;upload-&gt;display_errors('&lt;span&gt;', '&lt;/span&gt;'));
          } else {
              // upload success
              $upload_data = $this-&gt;upload-&gt;data();
              return true;
          }
      }
  </code></pre>
  
  <p>So what this basicly does is to upload images to an album. Also if the folder album does not exist already, it creates a new album.</p>
  
  <p>I was doing some tests and found out something that might be a small bug. While I was forcing my form to do some invalid upload attempts and the upload fails, as expected, but the album folder (suppose the album folder doesn't exist) is still created. </p>
  
  <p>Whouldn't make more sence to create the album folder if there are no erros and right before uploading the image and if yes how can I fix this??</p>