title: WordPress | Upload files and resize them
body: <p>I have develop a script that allowing the registered front end users to create their own posts, with a featured image for each post.</p>
  
  <p>While I have complete the overall process, the problem now is the image resizing.</p>
  
  <p>The script that manipulating the images is the following:</p>
  
  <pre><code>if(isset($files['rcp_user_logo']) &amp;&amp; $files['rcp_user_logo']['error'] == 0)
  {
      $uploadDir      =   wp_upload_dir();
      $updoadBase     =   $uploadDir['basedir'];
      $uploadURL      =   $uploadDir['baseurl'];
      $uploadLogos    =   $updoadBase . DIRECTORY_SEPARATOR . 'LfirmLogos' . DIRECTORY_SEPARATOR;
      $uploadLogosURL =   $uploadURL . '/LfirmLogos/';
      $dir_exists     =   false;                          //  Flag for directory existance
  
      if(($dir_exists = is_dir($uploadLogos)) == false)   //  If the upload dir is not exists
      {
          $dir_exists =   mkdir($uploadLogos, 0755);      //  Try to create the dir with 0755 permissions
                                                          //  If the dir will be successfully created
                                                          //  the $dir_exists will be set to true
                                                          //  otherwise will be set to false
      }
      else
      {
          $dir_exists = true;                             //  If upload dir exists then set
                                                          //  the $dir_exists to true
      }
  
      if($dir_exists  == true)
      {
          //  Set the tmpFile to the temporary uploaded file path
          $tmpFile    =   $files['rcp_user_logo']['tmp_name'];
          //  Set the new file to upload directory and name the file after the custom post ID
          $newFile    =   $uploadLogos . $new_id . '-' . $files['rcp_user_logo']['name'];
          //  Set the new file URL to updaload directory URL and name the file after the custom post ID
          $newFileURL =   $uploadLogosURL . $new_id . '-' . $files['rcp_user_logo']['name'];
  
          if(move_uploaded_file($tmpFile, $newFile))      //  If file has been
          {
              $wp_filetype    =   wp_check_filetype($files['rcp_user_logo']['name']);
  
              $attachment = array(
                  'guid'           =&gt; $newFileURL,
                  'post_mime_type' =&gt; $wp_filetype['type'],
                  'post_title'     =&gt; sanitize_title($files['rcp_user_logo']['name']),
                  'post_status'    =&gt; 'inherit'
              );
  
              $attachment_id = wp_insert_attachment($attachment, $newFileURL, $new_id);
  
              if($attachment_id != 0 )
              {
                  if(!function_exists('wp_generate_attachment_metadata'))
                  {
                      include( ABSPATH . 'wp-admin/includes/image.php' );
                  }
  
                  $attachment_data    =   wp_generate_attachment_metadata($attachment_id, $newFileURL);
                  $result = wp_update_attachment_metadata($attachment_id, $attachment_data);
                  $result = update_post_meta($new_id,   '_thumbnail_id',    $attachment_id);
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>NOTE :</strong> In order to keep me logos seperated from the default WordPress images I have create my own catalog under the /wp-content/uploads/ and I don't know if that is a reasong to prevent the image resizing.</p>
  
  <p><strong>NOTE :</strong> $new_id is the ID of the post created in the previews code programmaticaly.</p>
  
  <p><strong>NOTE :</strong> I also have used the plugin "AJAX Thumbnail Rebuild" but still no effect on the images. It cannot resize the images too.</p>
  
  <p><strong>NOTE :</strong> Images that are uploaded by the admin area, are properly resized.</p>
  
  <p>Is there any idea on how to solve that issue ?</p>
  
  <p>Kind regards</p>