This should work: $wp_upload_dir = wp_upload_dir(); $fileurl = “http://damianc.pl/th.jpg”; $filename = $upload_dir[‘path’] . DIRECTORY_SEPARATOR . basename( $fileurl ); if ( file_put_contents( $filename, file_get_contents( $fileurl ) ) ) { require_once(ABSPATH . ‘wp-admin/includes/image.php’); $wp_filetype = wp_check_filetype(basename($filename), null); $attachment = array( ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($filename)), ‘post_content’ => ”, ‘post_status’ => ‘inherit’ ); $attach_id = … Read more