I really like the way SE uploads an image from a URL (I’m sure many do!). I’ve been searching, but can’t find, is there a plugin or a method similar to this available for WordPress?
I know an image can be uploaded and crunched directly from a URL by entering the image URL into the File Name box after you click Upload/Insert Media >> From Computer >> Choose File
This is a great feature, but not very widely known (I actually just discovered it). I would like something a little more like SE, where there is an option that let the user know to add the image URL.
How can I go about adding simply the upload file field to a new tab in the media uploader?
Here is a tutorial for How to add a new tab in Media Upload page in wordpress, but I want to add only some text and the file upload field to that tab. Any ideas? I couldn’t find anything in the WordPress Codex that deals with this feature or the file upload field directly.
Thanks.
you can write a php script, or make your own plugin of this code here, i used it in one of my projects where i had to import a large number of images.
first, get the image, and store it in your upload-directory:
$uploaddir = wp_upload_dir();
$uploadfile = $uploaddir['path'] . "https://wordpress.stackexchange.com/" . $filename;
$contents= file_get_contents('http://mydomain.com/folder/image.jpg');
$savefile = fopen($uploadfile, 'w');
fwrite($savefile, $contents);
fclose($savefile);
after that, we can insert the image into the media library:
$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => $filename,
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $uploadfile );
$imagenew = get_post( $attach_id );
$fullsizepath = get_attached_file( $imagenew->ID );
$attach_data = wp_generate_attachment_metadata( $attach_id, $fullsizepath );
wp_update_attachment_metadata( $attach_id, $attach_data );
and voila – here we go.
you can also set various other parameters in the attachment array.
if you got an array of urls or something like that, you can run the script in a loop – but be aware that the image functions take up a lot of time and memory to execute.