• Welcome to Simple Machines Community Forum. Please login or sign up.
January 19, 2022, 07:17:41 PM

News:

SMF 2.1 RC4 has been released! Try it out and help us test! :) Read more.


Caching posted images

Started by Pripyat, April 30, 2014, 07:31:59 PM

Previous topic - Next topic

Pripyat

Is there any way for SMF to cache the images posted by users inside their posts (URLs in the [img] tags) so that they would be stored on some directory local to the server and served from there instead of from the external URL?

I mean, when some user writes his post, and inserts some image between the [img] tags, the script downloads that image from the URL provided by the user into some directory local to the server, and when this post is being displayed, it loads the image form that local directory instead of the original external URL. But when the user edits his post, he can still see the external URL (if he wanted to update it or something).

I ask about that, because I find many broken URLs to external images which doesn't exist anymore, but they're still referred from the posts on my forum. If they were stored locally, this wouldn't be a problem, since they could be then loaded from the local cache.

ѕησω

I can see that becoming problematic if on shared hosting.

I would suggest having users attach the images to posts instead, or upload them to dedicated file hosting sites were the url won't change.

"The Book of Arantor, 17:3-5
  And I said unto him, thy database query shalt always be sent by the messenger of $smcFunc
  And $smcFunc shall protect you against injections and evil
  And so it came to pass that mysql_query was declared deprecated and even though he says he is not dead yet, the time was soon to come to pass when mysql_query shall be gone and no more."

kat

I can see problems, too. Not least, of which, will be server space. Pictures take-up a lot of room, really quickly.

Pripyat

What about instead of seeking for problems and making assumptions, we focus on solutions and the details I described?
Shared hostings are not my problem, neither the server space.
The local directory will stay the same, and even if it not, the script could always generate the URL on the fly from the forum's config when displaying the post.
And I know this solution works, since I saw it working on one forum with lots of users, using Invision Power Board. It works like a charm, and users don't need to worry that whatever external images they embed in their posts, they will never become invalid and disappear. So I wonder if Simple Machines forum (which I use) could do that too somehow, because my users post a lot of images which often become invalid.

kat

Quote from: Pripyat on May 01, 2014, 11:45:04 AM
What about instead of seeking for problems and making assumptions

It's bad to foresee possible problems and try to obviate them? Tsk. Best not to ever do that, then, I suppose...

Other than posting the images as attachments, there's no way of doing this, with the vanilla SMF. There are mods, such as "Highslide", which make attachments a bit better, though. Maybe a search through the mods will turn something up, that does something like what you want.

One of these, maybe?

http://custom.simplemachines.org/mods/index.php?mod=2285

http://custom.simplemachines.org/mods/index.php?mod=1179

Biology Forums

QuoteI mean, when some user writes his post, and inserts some image between the [img] tags, the script downloads that image from the URL provided by the user into some directory local to the server, and when this post is being displayed, it loads the image form that local directory instead of the original external URL. But when the user edits his post, he can still see the external URL (if he wanted to update it or something).

Very cool idea. If you find a solution, let me know. However, I believe the script would have to run via post.php. The script would have to read the message via REGEX for [IMG] and somehow download it to the server prior to posting. It would require a lot more queries to work, but totally doable.

Illori

have you considered who owns the copyright of the images and if you are allowed to have them stored locally on your server?

Kindred

it would be a godsaweful mess of code and not great for system resources...

not to mention the legal implications as Illori noted
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Quote from: Pripyat on May 01, 2014, 11:45:04 AM
What about instead of seeking for problems and making assumptions, we focus on solutions and the details I described?

Because seeking problems and avoiding making too many assumptions is precisely how competent people in their field achieve their aims.

Specifically, as a relative expert in the field, it would be absolutely remiss of me to offer anything approaching a solution without having examined the possible consequences of doing so. If only to avoid implicating myself later on.

What I will tell you is that XenForo has it by default as of 1.3, where images default to only being cached for 7 days. They have asserted that the copyright aspects are not that problem. And yes, if you scrape images and hold them for any significant period of time, you could quite easily be in violation of copyright laws unless you can prove the images are suitably licensed. I know of a case last year where the forum owner was fined thousands of Euros for such matters. The software doing it automatically is not considered a defence. The short term caching is the only caveat that defends you in such situations.

The actual process of doing is not significantly difficult, though you may find yourself surprised with the server space consumed. Do note that 'unlimited' space is not unlimited and you will hit any limits on CPU long before you consume enough space to be problematic.


If you want users to post images, use attachments. But you're still just as liable for copyright as you are with images being locally stored.
No good deed goes unpunished
All helpful urges should be circumvented

Advertisement: