-1

I have a website, where images are like:

<img src="upload/test.jpg"/>

But I checked some larger sites and they have a different src as:

<img src="imgrur.com/9keqqq"/>

My question is, why they do like this?

Is that a security thing? Or to save space on the server?

And how can i do that in PHP? I am currently using WordPress.

3
  • Major websites have names like that in order to avoid multiple files with the same name. This is a good answer on how to rename images - stackoverflow.com/questions/13751377/… Commented Sep 30, 2018 at 3:25
  • The wordpress URL scheme for images is year/month/name. IIRC in the very unlikely event of name which already exists for that month wordpress will add a uniq suffix to the name, so no there is no need to fix a problem of "same name" as there is no such problem in wordpress. Commented Sep 30, 2018 at 4:13
  • I agree that the risk of a duplicate file name is not an issue. But the year/month/name scheme is a red herring. In fact it is merely the WordPress “default” scheme and many go to great lengths to avoid it, as the link provided by sampedraza shows.
    – Tedinoz
    Commented Sep 30, 2018 at 4:43

1 Answer 1

4

You've asked a good question... well, a couple of questions.

Considering the example at face value.

Larger sites have an image url like this. Why?

. <img src="imgrur.com/9keqqq"/>

There are any number of reasons but let's deal with the most obvious. "Imgur" is an example of a service that hosts "interesting" images and they encourage people to join and/or share those images. In the case you mention, the site (whether large or small) may want an image to emphasis something in a post; they don't have a suitable image, or their own stock, and they don't want to pay for a stock image (not in this example case at least), so instead they select an image from Imgur.

Is that a security thing? No.
Or to save space on the server? Possibly, but unlikely.

And how can i do that in PHP? I am currently using WordPress.

Easy. You don't have to know any PHP. WordPress does it all for you. When you click "Add Media" in the "Edit Post" screen, WordPress takes you to this screen. There's a menu option here that's not often noticed - "Insert from Url". enter image description here
Click the menu option: insert an url, and then add caption, alt text, alignment, and 'link to' as usual. Then click the "Insert into post" button. Here's the code inserted into the post. Much the same as usual except for the url. <insert image
Likewise, this is the html in the web page.
enter image description here

Considering the example in terms of website optimisation.

One possibility is a site (large or small) might be trying to optimise the performance of their website. The codex has a page on this: "WordPress Optimization", and there are plenty of other resources on the net. One of the options is "Offloading":

"Using a CDN can greatly reduce the load on your website. Offloading the searching and delivery of images, javascript, css and theme files to a CDN is not only faster but takes great load off your WordPress server's own app stack. A CDN is most effective if used in conjunction with a caching plugin.".

So says the codex; this is a simplistic statement and there is, as usual, much more to the issue than this. But this is enough to launch a reader onto the path of enlightenment ;)

This introduces the subject of a CDN (Content Delivery Network). Greater minds than mine have written on this, but for a quick, down-to-earth, no spin, primer "Adding and Leveraging a CDN on Your Website" at CSS-Tricks is as good a place as any to start.

Now your example and questions take on a different meaning, though funnily enough some the answers remain much the same.
Why do larger sites have a different url for, say, images? In order to improve the performance of their site. However, let me just add that Imgur is NOT a CDN and is NOT recommended as a substitute for a CDN.

Is that a security thing? No.
Or to save space on the server? Possibly, but not necessarily and unlikely.
And how can i do that in PHP? I am currently using WordPress. You add images in exactly the same way as described above.

Creating and using a CDN involves more than just signing up for a service but there are loads of step-by-step tutorials to be found - I Googled "tutorial using cdn with wordpress" (date 'Past year'). Normal rules apply - some may be better than others, some may be biased, some may be accurate/inaccurate, etc. My point is that there is plenty of information to be had.

4
  • Thanks for answer! but in my case, i cant add manually on wordpress, cause im using buddypress (social network) plugin. So on buddypress we have profiles, i want each profile update for example, be directly on imgrur for example instead of server. Do u know how can i do?
    – roger taht
    Commented Oct 1, 2018 at 14:02
  • This is a WordPress Development forum. You specifically said "I am currently using WordPress". Now you say you're not using WordPress? I suggest you spend 15 minutes Googling; you may find that your question has already been asked and answered. If not, there is a BuddyPress tag that applies in this forum and on StackOverflow. I suggest you write a new question, making sure to fully disclose what system you are using and what you are trying to do. Someone who knows something about BuddyPress might respond.
    – Tedinoz
    Commented Oct 1, 2018 at 16:23
  • buddypress its a wordpress plugin, that was a way to say the content its generate by users on a social network instead of by myself uploading images on wordpress. I tagged buddypress on thread, i just asked you cause maybe you already worked with buddypress
    – roger taht
    Commented Oct 1, 2018 at 18:02
  • BuddyPress is not tagged on this thread. You have written a completely misleading question and wasted my time and patience. If you have a question about BuddyPress, then follow my earlier advice. 1) do some research on your own because its pretty obvious that you've not bothered to do any so far. 2) if that is unsuccessful, then, write a new question (tagged as BuddyPress) making sure to fully disclose what system you are using, what you are trying to do, what research you've already done, what, EXACTLY, you are trying to achieve..
    – Tedinoz
    Commented Oct 2, 2018 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.