fksbuffalo Posted November 4, 2009 Share Posted November 4, 2009 I have the path to an image stored in my database like this... /var/www/vhosts/mysite.com/httpdocs/vieleRETS-1.1/j_image/20903057_1.jpg How do I get this image to display? Quote Link to comment https://forums.phpfreaks.com/topic/180315-absolute-to-relative-path/ Share on other sites More sharing options...
ram4nd Posted November 4, 2009 Share Posted November 4, 2009 <img src="vieleRETS-1.1/j_image/20903057_1.jpg" /> or(probably the first one) <img src="httpdocs/vieleRETS-1.1/j_image/20903057_1.jpg" /> Quote Link to comment https://forums.phpfreaks.com/topic/180315-absolute-to-relative-path/#findComment-951203 Share on other sites More sharing options...
fksbuffalo Posted November 4, 2009 Author Share Posted November 4, 2009 Sorry I should have explained better. I need this to be done automatically. I'm basically pulling random image paths from the database and need to display them. Quote Link to comment https://forums.phpfreaks.com/topic/180315-absolute-to-relative-path/#findComment-951224 Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2009 Share Posted November 4, 2009 If the document root portion is the same in all the entries, you can just do a simple string replace to remove it before you output it in the html. Quote Link to comment https://forums.phpfreaks.com/topic/180315-absolute-to-relative-path/#findComment-951233 Share on other sites More sharing options...
fksbuffalo Posted November 4, 2009 Author Share Posted November 4, 2009 If the document root portion is the same in all the entries, you can just do a simple string replace to remove it before you output it in the html. That sounds good. How do I do it? Quote Link to comment https://forums.phpfreaks.com/topic/180315-absolute-to-relative-path/#findComment-951253 Share on other sites More sharing options...
gizmola Posted November 4, 2009 Share Posted November 4, 2009 Answer depends on what the document root for your site is. You can get this from apache, via the $_SERVER['DOCUMENT_ROOT'] variable. Needless to say, if your site ever gets moved around, then this will all break -- so perhaps it would be good to fix up your application so that it no longer stores the absolute path to these images. Such a fix could be easily done against the database with a single update statement that would remove the portion which currently includes the Document root portion. In the short term however, you could fix up the paths using this simple code: // assumes that $imgpath has the retrieved path to the image from the db echo ''; Quote Link to comment https://forums.phpfreaks.com/topic/180315-absolute-to-relative-path/#findComment-951283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.