I’ve got a plugin that transfers some files over to the uploads folder of the site in which the plugin is installed.
It works fine, however, the images are not appearing in the Media Manager. I expect some database registration is involved.
Given the script below which copies the files into the directory, what command would I need to add to the loop to register each image for the media manager?
foreach(new RecursiveIteratorIterator($rdi) as $files)
{
if ($files->isFile())
{
$imagepath = $files->getRealPath();
$image = basename($files->getPathname());
copy($imagepath, $my_target_folder.'/'.$image);
}
}
add this to your for each and $filename to each file,
Have you looked at the function media_handle_sideload()? It seems to be what you’re looking for.
It works essentially the same way as media_handle_upload(), but takes a file thats already on the local server, moves it to the current uploads directory, and generates the post record necessary to add it to the Media Manager.