WordPress.org

Ready to get started?Download WordPress

Forums

Files are uploaded using plugin but cant find files in media (1 post)

  1. emertana
    Member
    Posted 1 year ago #

    I am using my plugin to retrieve files from a webservices and save them into my wordpress, it properly works and save them into the upload directory but I cant find them in media library.

    my code is as following

    require("/Applications/MAMP/htdocs/wordpress/wp-load.php");
    
    $Addr = "http://www.xxx.com" . $Addr;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_URL, $Addr);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    
    ini_set( 'display_errors', TRUE );
    error_reporting( E_ALL );
    
    $upload_dir = wp_upload_dir();
    $location= $upload_dir['basedir']. "/" . "a.jpg";
    
    file_put_contents($location, $output);
    echo 'Photo is uploaded';

Topic Closed

This topic has been closed to new replies.

About this Topic