/    Sign up×
Community /Pin to ProfileBookmark

best practice in saving image

I was wondering when I want to save an image location on my database is better to save only the image name or save the full URL?

For example I upload: cat.jpg

In database should I save “cat.jpg” and in my HTML (PHP) write:

[code=php]<img src=”http://WEBSITE/uploads/<?php echo $image?>”>[/code]

or save “http://WEBSITE/uploads/cat.jpg” and in HTML (PHP) have:

[code=php]<img src=”<?php echo $image?>”>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Shanu_chaudharyMay 13.2011 — Best way to save only the image name "cat.jpg" and to display the same image u can just use like this
[CODE]
<img src="<?php echo DIR_IMAGES.$image?>" />
[/CODE]


where DIR_IMAGES is a constant where u can specify the path of the images in a specific folder.

Hope this helps.
Copy linkTweet thisAlerts:
@XeroSiSauthorMay 13.2011 — Thanks, that sounds best.
Copy linkTweet thisAlerts:
@NogDogMay 13.2011 — Yeah, I definitely would not save the full URL, as web sites ten to have their directory structures change or even have their domain names changed at the most inconvenient times. ? If you keep the domain/path info separate and such that you only have to change it in one place, you can save yourself a lot of potential grief later.
×

Success!

Help @XeroSiS spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...