tags:

views:

36

answers:

2

any function to find my link files

example

i have host and i add images ,so i need image links to store it in database to reuse it

the function i need< will give my the link as this

www.mysite.com/folder/image.jpg

any one help plz

+1  A: 

Either find out the server name dynamically

<?php

function add_site_to_db_link($link) {
  return $_SERVER["SERVER_NAME"] . $link;
}

?>

but this may not work well with shared hosting, so you can replace $_SERVER["SERVER_NAME"] with 'www.mysite.com'

<?php

function add_site_to_db_link($link) {
  return 'www.mysite.com' . $link;
}

?>

you may also want to replace part of the path

<?php

function add_site_to_db_link($link) {
  return $_SERVER["SERVER_NAME"] . str_replace('./htdocs/images', '/img', $link);
}

?>
Metalshark
thank u for all but really i dont understand what is $link contain?contain what?
magy
$link was meant to contain the value from the database. So if your database value is './htdocs/images/cat.jpg' the first and second examples would return 'www.mysite.com./htdocs/images/cat.jpg' and the third will return 'www.mysite.com/img/cat.jpg'. Without knowing the database used we cannot show how to extract the 'link' value in your question.
Metalshark
A: 

If you store metadata (file name, path etc) in database, then just simply retrieve this information and compose it back to format which you need.

domain + path + file will result in www.example/path/to/file/fish.jpg

Table images

id | path | filename
1 | photos | fish.jpg
2 | icons | idea.png

Code

$domain = 'http://www.example.com/';
$path = 'files/' . $result['path'] . '/';
$image = $result['image'];
$link_to_image = $domain . $path . $image;
dwich