cheeseus Posted April 20, 2007 Share Posted April 20, 2007 Hi, I am rather new to php, so excuse my perhaps silly question. I want to have a root directory from which the images on different pages shall be displayed. I define it here: define('image_root', '/web/d2/w/mydomain/mydomain.com/images/'); Then I try to pass this path to the image: $imageurl = image_root . $myrow['image']; echo "<div id=left><img src='$imageurl' border=1></div>"; But it doesn't work... Any ideas? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/ Share on other sites More sharing options...
Michael Lasky Posted April 20, 2007 Share Posted April 20, 2007 How does it not work? Do you get an error? Does the image just not show up? If it's the latter, check to make sure both your $image_root and $myrow['image'] are set correctly . Or just check the whole string. $imageurl = image_root . $myrow['image']; echo "$imageurl <br>"; echo "<div id=left><img src='$imageurl' border=1></div>"; Make sure imageurl is correct Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234269 Share on other sites More sharing options...
cheeseus Posted April 21, 2007 Author Share Posted April 21, 2007 Thanks! I checked everything again, just to make sure, but the root directory is correctly set, and so is the 'image' row from the MySQL table. When I load the page, the "missing image" thingy appears. When I added this line: echo "$imageurl <br>"; above the "missing image" I get the path printed, i.e. '/web/d2/w/mydomain/mydomain.com/images/' Perhaps there is some other piece of code that has to be added to properly display it? Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234571 Share on other sites More sharing options...
Guest prozente Posted April 21, 2007 Share Posted April 21, 2007 What do you mean by "missing image thingy"? To me it looks like you are using the full path of the files for the operating system when you should be using the path regarding where your root web directory is. You are using /web/d2/w/mydomain/mydomain.com/images/ tho to me it looks like you should be using /images/ Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234610 Share on other sites More sharing options...
cheeseus Posted April 21, 2007 Author Share Posted April 21, 2007 Yep, you're quite right. It worked with /images/ . Thanks! The "thingy" is the small white box with a red X in it, when the image is missing Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234659 Share on other sites More sharing options...
cheeseus Posted April 21, 2007 Author Share Posted April 21, 2007 Sorry, it seems to work only when the page is in the same directory ??? I am trying to view the same info on a different page which is in another folder (/archive/), and the images are stored in the (./images/) directory. So I wrote: $image_root = './images/'; $imageurl = $image_root . $myrow['image']; ..... echo '<div id=right_floated><img src=".$imageurl." border=1></div>'; But the image doesn't show Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234667 Share on other sites More sharing options...
keeB Posted April 21, 2007 Share Posted April 21, 2007 The problem you may be having may lie in the way the browser reads $imageurl. Right click on the broken photo and go to 'Properties' - This will show you the path the browser is trying to render. INFO: The way browsers deal with paths is if http:// is not provided, everything in your SRC tag is posted AFTER your script path. Think of it this way. http://my.site.com/me/somescript.php tries to get an image in http://my.site.com/you/some_image.jpg $imageurl would have to be http://my.site.com/you/some_image.jpg in somescript.php Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234688 Share on other sites More sharing options...
cheeseus Posted April 21, 2007 Author Share Posted April 21, 2007 I think I understand. Means I have to write something like: $imageurl = "http://mysite.com/images/".$image; Yep, just tried it and it works. Thank you very much! But why doesn't giving the full path work, like in: define('image_root', '/web/d2/w/mysite/mysite.com/images/'); ... $imageurl = image_root . $myrow['image']; This is what I have in a script for comments, so I expected it to work here as well. Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234787 Share on other sites More sharing options...
Destramic Posted April 21, 2007 Share Posted April 21, 2007 try putting it in capitals [code[ <?php define("IMAGE_ROOT", "/web/d2/w/mysite/mysite.com/images/"); $imageurl = IMAGE_ROOT . $myrow['image']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/47930-solved-define-root-directory-for-images/#findComment-234797 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.