Téléchargement d'image depuis l'URL
-
-
Les demandes defonctionnalités appartiennent àtrac.wordpress.org.Feature requests belong on trac.wordpress.org.
- 0
- 2012-04-24
- Wyck
-
Pas une demande defonctionnalité.Lafonctionnalitéest déjàintégrée.Not a feature request. The feature is already built in.
- 2
- 2012-04-24
- Travis Pflanz
-
@TravisPflanz Je suistombé dessuspour Windowset j'aipensé que c'était dugénie - a définitivement améliorémonflux detravail.Vous savez detoutefaçonfaire cela sur Mac?command + shift +g ne semblepasprendreen charge les URL,maisn'étaitpas sûr s'il y avait une autre commande.@TravisPflanz Came across this for Windows and thought it was genius - definitely improved my workflow. Know of anyway to do that in Mac? command+shift+g doesn't seem to support urls, but wasn't sure if there was another command.
- 0
- 2017-11-08
- user658182
-
L'avantage dutéléchargement àpartir de l'urlpar rapport à «entrer l'url dans legestionnaire defichiers Windows»est que lefichierest chargé directement depuis la source vers le serveur wordpress;dansmon cas,sur la lignegigabit des centres d'hébergement au lieu d'être d'abordtéléchargé surmon PC,puis sur le wordpress sur une connexionmobile lente.The advantage of upload from url over the "enter url in windows filemanager" is that the file is loaded directly from the source to the wordpress server; in my case over the hosting centers gigabit line instead of first being downloaded to my pc and then up to the wordpress over slow mobile connection.
- 0
- 2018-01-31
- Lenne
-
L'astucepour ``télécharger '' directement àpartir d'une URLne fonctionnepas sous Windows 10 (dansn'importe quelnavigateur -testé Firefox,Chrome,IE11),et n'aprobablementpasfonctionné dans les versionsprécédentes de Windows depuis 2012. Windowstéléchargera lefichier àpartir de l'URLvers unemplacementtemporaire sur votre ordinateuret télécharger àpartir de là.Iln'est doncpaspossible d'utiliser cette astucepour 'télécharger' degrosfichiers vidéo (pour contourner lefournisseur d'hébergement [HTTP 413] (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413)réponse avantmême que PHPet WordPressne soient consultés).The trick to 'upload' directly from a URL does not work in Windows 10 (in any browser - tested Firefox, Chrome, IE11), and has probably not worked in previous versions of Windows since 2012. Windows will download the file from the URL to a temporary location on your computer and upload from there. So it is not possible to use this trick to 'upload' large video files (to bypass hosting provider's [HTTP 413](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413) response before PHP and WordPress even get a look-in).
- 0
- 2019-10-31
- Jake
-
4 réponses
- votes
-
- 2012-05-02
Répertoire desplugins WordPress - Grab & amp;Enregistrer
Ceplugin vouspermet de récupérer uneimage depuis une URL distanteet de l'enregistrer dans votre propremédiathèque wordpress.Cefaisant,vousne vousinquiétezjamais si le l'image distante a été suppriméepar sonpropriétaire.Cela vous évite également des étapespour télécharger l'image sur l'ordinateur localet latélécharger ànouveau sur le vôtre wordpress.
Après avoir saisi l'image,wordpress vousinvitera à "insérer dans lapublication "ou"modifier les attributs "comme après avoirtéléversé uneimage.
WordPress Plugin Directory - Grab & Save
This plugin allow you to grab image from remote url and save into your own wordpress media library. By doing so, you never worried if the remote image was removed by its owner. This also save you steps to download the image to local computer and upload again to your own wordpress.
After grabbing the image, wordpress will prompt you either to "insert into post" or "change attributes" just like after you upload an image.
-
- 2012-04-30
vouspouvez écrire un scriptphp,ou créer votrepropreplugin de ce codeici,je l'ai utilisé dans l'un demesprojets oùj'ai dûimporter ungrandnombre d'images.
Tout d'abord,récupérez l'imageet stockez-la dans votre répertoire detéléchargement:
$uploaddir = wp_upload_dir(); $uploadfile = $uploaddir['path'] . '/' . $filename; $contents= file_get_contents('http://mydomain.com/folder/image.jpg'); $savefile = fopen($uploadfile, 'w'); fwrite($savefile, $contents); fclose($savefile);
après cela,nouspouvonsinsérer l'image dans lamédiathèque:
$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 );
et voilà - c'estparti. vouspouvez également définir divers autresparamètres dans letableau despiècesjointes. si vous avez untableau d'urls ou quelque chose comme ça,vouspouvezexécuter le scripten boucle -mais sachez que lesfonctions d'imageprennentbeaucoup detempset demémoire àexécuter.
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'] . '/' . $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.
-
oh,je suis désolé,je n'aipas vu l'image au début.peut-être quej'écrirai unpetit pluginfaisantexactement cela.J'espère que vouspouvez vousentendre avecmon scriptjusqu'àprésent -je voustiendrai au courant desnouvelles duplugin.oh, i'm sorry, i didn't see the image at first. maybe i will write a small plugin doing exactly this. i hope you can get along with my script so far - i will keep you posted on plugin news.
- 0
- 2012-04-30
- fischi
-
Jepense quej'ai ajouté l'image comme vous l'avezpostée.J'examineraiplusen profondeur àmon retour du déjeuner.Mercipour votre aide!Toujours apprécié.I think I added the image just as you posted. I will take a more in-depth look when I get back from lunch. Thanks for your assistance! Always appreciated.
- 0
- 2012-04-30
- Travis Pflanz
-
l'utilisation de `file_get_contents` avec une URLne fonctionnerapas si` allow_url_fopen`est désactivé dans `php.ini` - [` wp_remote_get`] (https://codex.wordpress.org/Function_Reference/wp_remote_get) seraplus hautement compatibledifférentsenvironnements WPusage of `file_get_contents` with a URL will not work if `allow_url_fopen` is disabled in `php.ini` - [`wp_remote_get`](https://codex.wordpress.org/Function_Reference/wp_remote_get) will be more highly compatible across different WP environments
- 0
- 2017-02-24
- highvolt
-
Salut,mercipour la réponse,car qu'est-ce que `wp_generate_attachment_metadata`et` wp_update_attachment_metadata`?Hi, thanks for the answer, for what is `wp_generate_attachment_metadata` and `wp_update_attachment_metadata` ?
- 0
- 2019-01-25
- gdfgdfg
-
C'estbien,mais commentpuis-je l'obtenirpourgénérer une vignette debibliothèquemultimédiaet plusieurstailles d'image?This is nice, but how do I get it to generate a Media Library thumbnail and multiple image sizes?
- 0
- 2020-05-18
- Robert Andrews
-
- 2017-01-06
Vouspouvez utiliser lesfonctions
download_url()
etwp_handle_sideload()
.Télécharge une URL dans unfichiertemporaire local à l'aide de la classe HTTP WordPress. Veuilleznoter que lafonction appelante doit dissocier () lefichier.
Gérez les charges latérales,c'est-à-dire leprocessus de récupération d'un élémentmultimédia depuis un autre serveur au lieu d'untéléchargementmultimédiatraditionnel. Ceprocessusimplique denettoyer lenom defichier,de vérifier lesextensionspour letypemime et de déplacer lefichier vers le répertoire approprié dans le répertoire detéléchargement.
Exemple:
// Gives us access to the download_url() and wp_handle_sideload() functions require_once( ABSPATH . 'wp-admin/includes/file.php' ); // URL to the WordPress logo $url = 'http://s.w.org/style/images/wp-header-logo.png'; $timeout_seconds = 5; // Download file to temp dir $temp_file = download_url( $url, $timeout_seconds ); if ( !is_wp_error( $temp_file ) ) { // Array based on $_FILE as seen in PHP file uploads $file = array( 'name' => basename($url), // ex: wp-header-logo.png 'type' => 'image/png', 'tmp_name' => $temp_file, 'error' => 0, 'size' => filesize($temp_file), ); $overrides = array( // Tells WordPress to not look for the POST form // fields that would normally be present as // we downloaded the file from a remote server, so there // will be no form fields // Default is true 'test_form' => false, // Setting this to false lets WordPress allow empty files, not recommended // Default is true 'test_size' => true, ); // Move the temporary file into the uploads directory $results = wp_handle_sideload( $file, $overrides ); if ( !empty( $results['error'] ) ) { // Insert any error handling here } else { $filename = $results['file']; // Full path to the file $local_url = $results['url']; // URL to the file in the uploads dir $type = $results['type']; // MIME type of the file // Perform any actions here based in the above results } }
You can use the functions
download_url()
andwp_handle_sideload()
.Downloads a url to a local temporary file using the WordPress HTTP Class. Please note that the calling function must unlink() the file.
Handle sideloads, which is the process of retrieving a media item from another server instead of a traditional media upload. This process involves sanitizing the filename, checking extensions for mime type, and moving the file to the appropriate directory within the uploads directory.
Example:
// Gives us access to the download_url() and wp_handle_sideload() functions require_once( ABSPATH . 'wp-admin/includes/file.php' ); // URL to the WordPress logo $url = 'http://s.w.org/style/images/wp-header-logo.png'; $timeout_seconds = 5; // Download file to temp dir $temp_file = download_url( $url, $timeout_seconds ); if ( !is_wp_error( $temp_file ) ) { // Array based on $_FILE as seen in PHP file uploads $file = array( 'name' => basename($url), // ex: wp-header-logo.png 'type' => 'image/png', 'tmp_name' => $temp_file, 'error' => 0, 'size' => filesize($temp_file), ); $overrides = array( // Tells WordPress to not look for the POST form // fields that would normally be present as // we downloaded the file from a remote server, so there // will be no form fields // Default is true 'test_form' => false, // Setting this to false lets WordPress allow empty files, not recommended // Default is true 'test_size' => true, ); // Move the temporary file into the uploads directory $results = wp_handle_sideload( $file, $overrides ); if ( !empty( $results['error'] ) ) { // Insert any error handling here } else { $filename = $results['file']; // Full path to the file $local_url = $results['url']; // URL to the file in the uploads dir $type = $results['type']; // MIME type of the file // Perform any actions here based in the above results } }
-
J'ai utilisé ce codeet il a ajouté avec succès l'image dans le répertoire destéléchargements,mais lorsqueje vais dansmabibliothèquemultimédia dans lebackend Wordpress,je ne letrouvenullepartet iln'apparaîtpas dans la recherche.Jeme suis assuré qu'il avait les autorisations correctesmaistoujourspas de chance.Une raisonpour laquelleiln'apparaîtraitpas?I Used this code and it successfully added the image in the uploads directory but when i go to my Media Library in the Wordpress backend I cant find it anywhere and it does not show up in the search. I made sure it had correct permissions but still not luck. Any reason it wouldn't be showing up?
- 0
- 2018-06-14
- Nick
-
Iln'ajouterapas d'entrées côté administrateur.Si vous souhaitez ajouter desentrées dans admin,mieux vaut utiliser, wp_insert_attachment (); https://codex.wordpress.org/Function_Reference/wp_insert_attachment ou vouspouvez l'utiliseren modifiant la variableglobale $ _FILES. media_handle_upload (); https://codex.wordpress.org/Function_Reference/media_handle_uploadIt will not add entries in admin side. If you want to add entries in admin, then better you can use, wp_insert_attachment(); https://codex.wordpress.org/Function_Reference/wp_insert_attachment or you can use this by modifiying $_FILES global variable. media_handle_upload(); https://codex.wordpress.org/Function_Reference/media_handle_upload
- 0
- 2018-06-20
- Rajilesh Panoli
-
çane marchepas dutoutit doesnt work at all
- 0
- 2019-05-08
- iKamy
-
- 2016-12-12
Ilexiste aumoinstroisfaçons d'importer desimages distantes dans WordPress:
-
Grab and Save Plugin ,quiestmentionné dans l'autre répondre. Ceplug-inest unpeuplus ancienet ilenregistre lefichier directement,de sorte que les vignettes de différentestaillesne sontpas créées. Dernièremise àjouril y aplus de 2 ans aumoment de la rédaction.
-
Import External Image Plugin permet uneimportationgroupéepour lesimages liées à distance . Vous devrezpeut-être augmenter votre limite demémoire PHPpour que celafonctionne. Dernièremise àjouril y aplus de 2 ans aumoment de la rédaction.
-
Enregistrer & amp; Importer uneimage àpartir duplugin URL importe l'imageen utilisant desfonctionsnatives,afin qu'elle soit correctement créée dans lagaleriemultimédiaet quetoutes les vignettes,etc. soient créées. Ceplugin a étémis àjourpour la dernièrefoisen 2016et fonctionne avec WordPress 4.7
Divulgation:j'ai créé le Save & amp; Importer uneimage àpartir duplug-in d'URL
There are at least three ways to import remote images into WordPress:
Grab and Save Plugin, which is mentioned in the other answer. This plug-in is a bit older and it saves the file directly, so thumbnails in different sizes are not created. Last update over 2 years ago at the time of writing.
Import External Image Plugin has bulk import for remote linked images. You may need to increase your PHP memory limit for this to work. Last update over 2 years ago at the time of writing.
Save & Import Image from URL Plugin imports the image using native functions, so it is properly created in the media gallery and all thumbnails etc. are made. This plugin is last updated in 2016 and works with WordPress 4.7
Disclosure: I created the Save & Import Image from URL Plugin
-
Je vous remercie!Connaissez-vous lesplugins compatibles avec les versions actuelles de Wordpress (5.4)?thank you! Do you know about plugins compatible with current Wordpress versions (5.4)?
- 0
- 2020-04-10
- cduguet
J'aimebeaucoup lafaçon dont SEtélécharge uneimage àpartir d'une URL (je suis sûr quebeaucoup lefont!). J'ai cherché,maisje netrouvepas,existe-t-il unplugin ou uneméthode similaire à celui-ci disponiblepour WordPress?
Je sais qu'uneimagepeut être téléchargéet analysé directement àpartir d'une URL en entrant l'URL de l'image dans la zone Nom defichier après avoir cliqué sur Télécharger/Insérer unmédia >> Depuis l'ordinateur >> Choisir unfichier
C'est unefonctionnalitéintéressante,maispeu connue (je viens de la découvrir). Je voudrais quelque chose d'unpeuplus comme SE,oùilexiste une optionpermettant à l'utilisateur d'ajouter l'URL de l'image.
Commentpuis-je ajouter simplement le champ defichier àtélécharger dans unnouvel onglet de l'outil detéléchargementmultimédia?
Voici untutorielpour Comment ajouter unnouvel onglet dans lapage detéléchargement demédia dans wordpress ,maisje veux ajouter seulement dutexteet le champ detéléchargement defichier à cet onglet. Desidées? Jen'ai rientrouvé dans le Codex WordPress quitraite directement de cettefonctionnalité ou du champ detéléchargement defichier.
Merci.