Jump to content

[SOLVED] define root directory for images


cheeseus

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Guest prozente

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/

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.