title: Upload a file to specific folder using WordPress
body: <p>I need help for how to upload a file in WordPress, I don't want to upload files into the default path of media files i.e. into <code>uploads/../..</code>, I want to upload my files into <code>wp-content/uploads/my_folder</code>, I just created one file in <code>wp-admin</code> folder and added some functionality there, from that form I want to upload my file (not creating plugin).</p>
  
  <p>Is it possible to do like this? If yes then how? If no then what I want to do for uploading file?</p>
  
  <p>I tried the following solution for it:</p>
  
  <pre><code>    $path_array  = wp_upload_dir();
      $upload_path = $path_array['baseurl'].'/myfoldername/';
      $target_path = $upload_path."/".$file_name;
      $file_name = $_FILES['fieldname']['name'];
      $tmp_name = $_FILES["fieldname"]["tmp_name"];
  
      upload_user_file($_FILES,$upload_path); // Called this function
  </code></pre>
  
  <p>In <code>functions.php</code> of my theme, I defined the above called function <code>upload_user_file()</code> like as follows:</p>
  
  <pre><code>function upload_user_file( $file = array(),$path) {
      if(!empty($file)) 
      {
          $uploaded=move_uploaded_file($file['fieldname']['tmp_name'],$path.$file['fieldname']['name']);
         if($uploaded) 
         {
             echo "Uploaded successfully ";
         }
         else
         {
              echo "Some error in upload ";
              print_r($file['error']);
         }
      }
  }
  </code></pre>
  
  <p>Please help me for this issue.</p>
  
  <p>Thanks. </p>