I've Created a Script that Grabs an image from an external site and it is imported to the WordPress image gallery. -> wp-admin/upload.php [Media Library]
My Code Snipplet
foreach($url as $linkurl) {
$tmp = download_url( $linkurl);
preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $linkurl, $matches);
$clean = str_replace(array("%2B", "%52", "%20", "%5"), "B", basename($matches[0]));
$file_array = array(
'name' => basename( $clean ),
'tmp_name' => $tmp
);
if ( is_wp_error( $tmp ) ) {
@unlink( $file_array[ 'tmp_name' ] );
return $tmp;
}
$id = media_handle_sideload( $file_array, $post_id, 'gallery desc' );
$value = wp_get_attachment_url( $id );
update_post_meta($post_id, array_push($post_id, '_product_image_gallery', $id));
//update_post_meta($post_id, array_push($post_id, '_product_image_gallery', $value ));
}
What am I doing Wrong