coderb Posted January 4, 2008 Share Posted January 4, 2008 Hi all, A newbie question. How do I define the full URL in my html image? So instead of <img src="images/top_invoice.gif" width="560" height="33"/> I'd like, something like <img src=.relative url./images/top_invoice.gif" width="560" height="33"/> thanks Quote Link to comment https://forums.phpfreaks.com/topic/84533-using-full-url-for-img/ Share on other sites More sharing options...
coderb Posted January 4, 2008 Author Share Posted January 4, 2008 Let me rephrase the question: Is there a maybe a host variable or function that gives me the full URL of the current page? thanks Quote Link to comment https://forums.phpfreaks.com/topic/84533-using-full-url-for-img/#findComment-430699 Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Share Posted January 4, 2008 Depends on how you want to pass that information. If you used a set variable then you'd just do this: $imagepath = "/path/to/image"; <img src="$imagepath/images/top_invoice.gif" width="560" height="33"> Quote Link to comment https://forums.phpfreaks.com/topic/84533-using-full-url-for-img/#findComment-430700 Share on other sites More sharing options...
coderb Posted January 4, 2008 Author Share Posted January 4, 2008 I'll explain how I'm trying to use it. I'm building an html page dynamically, previewing the content in the current page and then writing it as page.html page.html is written to a different directly, so now I have the problem that images dynamically added have the wrong path. To fix this I would need to use an absolute/full URL for the image location, but don't want to hardcode it. just thought there must be a way to get the full path of a current location? thanks Quote Link to comment https://forums.phpfreaks.com/topic/84533-using-full-url-for-img/#findComment-430712 Share on other sites More sharing options...
drummer101 Posted January 4, 2008 Share Posted January 4, 2008 <?php echo "<img src=\"" . $_SERVER['PHP_SELF'] . "/images/top_invoice.gif\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84533-using-full-url-for-img/#findComment-430720 Share on other sites More sharing options...
comstarters Posted January 4, 2008 Share Posted January 4, 2008 Hi all, A newbie question. How do I define the full URL in my html image? So instead of <img src="images/top_invoice.gif" width="560" height="33"/> I'd like, something like <img src=.relative url./images/top_invoice.gif" width="560" height="33"/> thanks If your domain is test.com If you want relative url, relative path or root path. '<img src=' . $_SERVER['DOCUMENT_ROOT'] . '/images/top_invoice.gif' etc..... would yeild www.test.com/images/top_invoice.gif Would allow you to have just one images folder instead of an images folder in every folder which you will need if using: "<img src=\"" . $_SERVER['PHP_SELF'] . "/images/top_invoice.gif\">"; would yeild www.test.com/current_folder/images/top_invoice.gif Quote Link to comment https://forums.phpfreaks.com/topic/84533-using-full-url-for-img/#findComment-430790 Share on other sites More sharing options...
drummer101 Posted January 4, 2008 Share Posted January 4, 2008 Hi all, A newbie question. How do I define the full URL in my html image? So instead of <img src="images/top_invoice.gif" width="560" height="33"/> I'd like, something like <img src=.relative url./images/top_invoice.gif" width="560" height="33"/> thanks If your domain is test.com If you want relative url, relative path or root path. '<img src=' . $_SERVER['DOCUMENT_ROOT'] . '/images/top_invoice.gif' etc..... would yeild www.test.com/images/top_invoice.gif Would allow you to have just one images folder instead of an images folder in every folder which you will need if using: "<img src=\"" . $_SERVER['PHP_SELF'] . "/images/top_invoice.gif\">"; would yeild www.test.com/current_folder/images/top_invoice.gif To fix this I would need to use an absolute/full URL for the image location' date=' [b']but don't want to hardcode it.[/b] just thought there must be a way to get the full path of a current location? Quote Link to comment https://forums.phpfreaks.com/topic/84533-using-full-url-for-img/#findComment-430804 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.