MyBB Community Forums

Full Version: Fetch remote posted images and store them locally [barely tested script]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
After brad brought up the idea of fetching remotely hosted images included in posts and hosting them locally, I decided to make a simple script to do just that that could be ran via a cron job. I've only tested it a little bit on my localhost today and it seems to be working just fine.

The script can be found here: https://github.com/euantor/MyBB-Local-Images

To use it, you will have to modify the definitions at the top of the file to suit your site and I definitely don't recommend using it live without first trying it locally and backing up your database fully.

The script itself can be ran via cron job or accessed directly via your browser. Either way, it will simply output the number of posts that were modified.

If anybody can test this out and post back results, I would be very glad indeed.
it would be nice if you would add a source URL after the img tag you add for proper credit. maybe style it with a <br /><span class="smalltext">Source: URL</span>
That would be entirely possible, didn't think of that at all. I'll add that in next time I make a commit.
Will test this tomorrow Euan.

Sounds like a great idea.
Thanks. I have also made pavemen's suggested change in the most recent commit.
Is that optional? IMO it's not really necessary. I'm not anti-credit by any means but the hosted source is not necessarily the original source. I predict lots of "source: imgur.com/blahblah".
then edit the code to not show it, but I would really appreciate it if people would credit images they pulled from my sites and since this code runs automatically, its not like the user that is remote linking has the option to maintain credits.
As pavemen said, it can be easily removed. I'll add a setting to make it even easier to remove too though.
Sounds like a great idea, well done for getting this working.

I get annoyed at seeing a lot of tinypic error messages in old threads so that would be great for forums.

Few questions - Will it edit all images on older posts? E.G. if you add it to a forum with 10,000 posts will it go back through them and upload them? Or does it just work from fresh install?
Right now it only works on a 24 hour basis, so the furthest it will go back is 24 hours. I've done this because processing 10,000 posts or whatever might well kill a server (especially a shared one). The script can easily be modified to work through older posts if you so wish though.
Pages: 1 2 3