title: Wordpress copy to uploads directory creates 0 bytes files
body: <p>For some reason, this code I've been working with since the beginning seems to have stopped working on my dev environment which is set up on a free hosting service. However, it still works locally. Now, I can't recall if I've ever actually tested it on the dev environment so maybe it never worked there to begin with.</p>
  
  <p>Basically, I'm using Gravity Forms to create custom posts (works just fine) and am also using multiple file uploads to add image attachments to the post. Since that's not entirely supported by GF yet I fiddled around and managed to create this little function here:</p>
  
  <pre><code>function create_post_attachment_from_gf($f, $from_url) {
      //for image field, it sends content with a bunch of other parameters in a string with pipe delimiters
      $split_image = explode('|', $from_url);
      if( count($split_image) &gt; 0 )
          $from_url = $split_image[0];
  
      if( !empty( $_FILES[$f]['name'] ) ) {
          $file = $_FILES[$f];
  
          $uploads = wp_upload_dir( null );
          $filename = wp_unique_filename( $uploads['path'], $file['name'], null );
          // Strip the query strings.
          $filename = str_replace('?','-', $filename);
          $filename = str_replace('&amp;','-', $filename);
  
          // Compute the URL
          $url = $uploads['url'] . "/$filename";
  
          $new_file = $uploads['path'] . "/$filename";
  
          copy($from_url,$new_file);
  
          // Move the file to the uploads dir
          $stat = stat( dirname( $new_file ));
          $perms = $stat['mode'] &amp; 0000666;
          @ chmod( $new_file, $perms );
  
  
          return array( 'file' =&gt; $new_file, 'url' =&gt; $url, 'type' =&gt; $file['type'], 'name' =&gt; $file['name'] );
      }
  
      return false;
  }
  </code></pre>
  
  <p>And then call it this way to create the attachment:</p>
  
  <pre><code>$copied_file = create_post_attachment_from_gf('input_' . $file_uploads[$i], $entry[$file_uploads[$i]]);
      $subdir = wp_upload_dir( null )["subdir"];
          if( $copied_file ){
              $attachment = array(
                  'guid' =&gt; $copied_file['url'], 
                  'post_mime_type' =&gt; $copied_file['type'],
                  'post_title' =&gt; $copied_file['name'],
                  'post_content' =&gt; '',
                  'post_status' =&gt; 'inherit'
              );
  
  
              $attach_id = wp_insert_attachment( $attachment, $subdir . '/' .$copied_file['name'], $post_id );
  
              $attach_data = wp_generate_attachment_metadata( $attach_id, $copied_file['file'] );
              wp_update_attachment_metadata( $attach_id,  $attach_data );
  
          }
  </code></pre>
  
  <p>It looks like the copy is what fails here. It creates an empty file in my uploads folder with the right filename. I checked my folder permissions and even went ahead and set everything under uploads (including the gravity forms folders) to 777 and it still doesn't work for some reason. </p>
  
  <p>Both my local and remote websites are running on WP 3.8.1 and all plugins are up to date on both. The databases are pretty much exactly the same aside from some test data which shouldn't interfere with this. Adding an attachment directly from the dashboard works fine. Is this something I should take up with the hosting company? Or is my code faulty? Or maybe there's a way to create an attachment without moving the file - that'd be fine with me. </p>
  
  <p>Any help is appreciated.</p>