MyBB Community Forums

Full Version: Download embeded images to local Server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Embedded Images rely on other hosts and once they get deleted a thread or post become useless there should be an option for admin/moderators to download whole thread's images or selected posts images to local server ...

A practical example can be seen at http://justpaste.it
where embedded images automatically downloaded to local server.....

Any suggestions for such plugin how to start ?

downloading images to local server seems easy but where should I include it in mybb???


function save_image($inPath,$outPath)
{ //Download images from remote server
$in= fopen($inPath, "rb");
$out= fopen($outPath, "wb");
while ($chunk = fread($in,8192))
{
fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
}

save_image('http://www.someimagesite.com/img.jpg','image.jpg');
Here's a useful script by Euan T. which automatically downloads remote images. https://github.com/euantorano/MyBB-Local-Images
I was just going to mention my script Wink Its best ran as a task or a cron job on the server.
(2014-07-04, 08:38 AM)Shade Wrote: [ -> ]Here's a useful script by Euan T. which automatically downloads remote images. https://github.com/euantorano/MyBB-Local-Images

thanks Heart

(2014-07-04, 09:08 AM)Euan T Wrote: [ -> ]I was just going to mention my script Wink Its best ran as a task or a cron job on the server.

Thansks it looks great but what I understood it will extract all images from all threads/posts right? but what about providing this feature as a moderator feature/tool for individual threads /posts ???coz not all threads are worthy for someone who is not hosting under expensive servers/hosting packages ....
Yes, it will extract all images from all posts over a day old, but skip any hosted locally (eg: attachments).
(2014-07-04, 10:26 AM)Euan T Wrote: [ -> ]Yes, it will extract all images from all posts over a day old, but skip any hosted locally (eg: attachments).

ok that great I have checked your script made some changes and it seems working for me,
Just one more thing Along with image urls enclosed within [img] tags, i want straight image urls without tags to be extracted as well e.g www.xyz.com/11.jpg

what modification is required in your follwoing regex expression

preg_match_all("#(?P<wholestring>\[img\](\r\n?|\n?)(?P<url>https?://([^<>\"']+?))\[/img\])#ise", $result->message, $matches);

Huh
That's a little more difficult. You'd need a Regex to match URLs (difficult enough) ending in a valid image extension.