ashwad ashwad - 4 months ago 17x
PHP Question

How Can I pass an image file to wp_handle_upload?

I have been looking everywhere for this and not able to find an answer.

I need to pass a file from the url source to wp_handle_upload. How can I accomplish this?

Thank you, hopefully i`ll get the answer


Refer this link

function my_enqueue_media_lib_uploader() {

    //Core media script

    // Your custom js file
    wp_register_script( 'media-lib-uploader-js', plugins_url( 'media-lib-uploader.js' , __FILE__ ), array('jquery') );
    wp_enqueue_script( 'media-lib-uploader-js' );
add_action('admin_enqueue_scripts', 'my_enqueue_media_lib_uploader');


  var mediaUploader;

  $('#upload-button').click(function(e) {
    // If the uploader object has already been created, reopen the dialog
      if (mediaUploader) {;
    // Extend the object
    mediaUploader = ={
      title: 'Choose Image',
      button: {
      text: 'Choose Image'
    }, multiple: false });

    // When a file is selected, grab the URL and set it as the text field's value
    mediaUploader.on('select', function() {
      attachment = mediaUploader.state().get('selection').first().toJSON();
    // Open the uploader dialog;


<form method="post">
    <input id="image-url" type="text" name="image" />
    <input id="upload-button" type="button" class="button" value="Upload Image" />
    <input type="submit" value="Submit" />