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
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
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);
}
?>
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;