Add new image to media library

Discussion in 'WordPress' started by valchy, Jul 19, 2012.

  1. #1
    Hi.
    I downloaded an image from outside Wordpress on the specific folder for media but it doesn't show the image on the admin panel media. What I would like to do is to write a short php code that uses wordpress to add the image from the link: wp-content/uploads/2012/07/test_image.jpg the same way that you add it from admin panel.
    Thank you in advance.
     
    Last edited: Jul 19, 2012
    valchy, Jul 19, 2012 IP
  2. valchy

    valchy Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I try to write a php code to create posts from outside wordpress admin panel, so I need to add an image to the media library. I keep trying to figure out how but I haven't managed to find something that I want.
    I'm trying something like this:
    1. download the image from the source website (curl) - done.
    now, the image is on the folder "wp-content/2012/07/" and the name of the image is image.jpg.
    2. what I need now is the php code to enter this image in the media library so it can be seen from the admin panel.
    i know i need to create an array with the image data and insert it into the database but I don't know how. I'm not an expert in php ...
     
    valchy, Aug 4, 2012 IP
  3. valchy

    valchy Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I wrote some code:

    include "wp-includes/plugin.php";
    include "wp-admin/includes/media.php";
    include "wp-admin/includes/file.php";
    $file = "http://images.1channel.ch/thumbs/2135197_Rock_of_Ages_2012.jpg";
    $post_id = 1;
    $desc = "testare upload";
    media_sideload_image($file, $post_id, $desc);


    but I get this message:

    Fatal error: Call to undefined function __() in C:\xampp\htdocs\wp-admin\includes\file.php on line 11
     
    valchy, Aug 4, 2012 IP
  4. Pepdeal

    Pepdeal Peon

    Messages:
    149
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Go to the settings-> Linked Image and click "process"
     
    Pepdeal, Aug 8, 2012 IP