I can't figure out how to get the relative image url to the photo of the person. The mobile site (see attachment) is in a folder (highlighted green) inside of the root of the site, and the images of the people are in the root images folder (highlighted in red), and NOT the mobile images folder. How do I tell "$row[pic_url]" to go back to the root folder before executing the command?
Announcement
Collapse
No announcement yet.
Help with Relative Image URL in PHP
Collapse
X
-
Would I do...?
PHP Code:<?php echo "<img src=\"$_SERVER['DOCUMENT_ROOT'] . '$row[pic_url]''" ?>
Last edited by Psionicsin; Aug 24, 2011, 05:25 PM.
-
-
Originally posted by Nightfire View Post<img src=\"/images/sencha/" .$row['pic_url']. "\"/>
And I believe I implemented your code wrong as I'm getting an error. I did this:PHP Code:<?php echo "<img src=\"/images/sencha/" .$row['pic_url']. "\"/>" ?>
PHP Code:<img src="/images/sencha//images/sencha/garban-gc.jpg"/>
Last edited by Psionicsin; Aug 25, 2011, 02:24 PM.
Comment
-
-
That is because inside your $row['pic_url'] you have put the whole url path in it. You just need to have the image name within it, then use what NightFire suggested.Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
I always recommend the HEAD First series of books for learning a new coding language. ^_^
Comment
-
-
Originally posted by Chris Hick View PostThat is because inside your $row['pic_url'] you have put the whole url path in it. You just need to have the image name within it, then use what NightFire suggested.
PHP Code:<?php
require_once('templates/mysql_connect.php');
?>
<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
?>
<div class="contents">
<h1><?php echo $row['first_name'], " ", $row['last_name']; ?></h1>
<h4><?php echo $row['school']; ?></h4>
</div>
<?php echo "<img src=\"/images/sencha/" .$row['pic_url']. "\"/>" ?> <br />
<br />
<a href="/">{{VOTEBUTTON}}</a>
So you guys are telling me that there's absolutely no code to add that will make it back out one directory BEFORE searching for the file???Last edited by Psionicsin; Aug 26, 2011, 10:53 PM.
Comment
-
-
I'm able to get it to show using the absolute URL of the image like:
PHP Code:<?php echo "<img src=\"http://www.rutholsonphoto.com" .$row['pic_url']. "\"/>" ?>
PHP Code:<?php echo "<img src=\"INSERT_CODE_RELATIVE_TO_CURRENT_DIRECTORY" .$row['pic_url']. "\"/>" ?>
Comment
-
-
Have you not already applied .. to the url such as this?
PHP Code:<?php echo "<img src=\".." .$row['pic_url']. "\"/>" ?>
Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
I always recommend the HEAD First series of books for learning a new coding language. ^_^
Comment
-
-
You do not need this to be relative.
HTML paths work different than PHP ones. PHP being server side can access the filesystem, while HTML only access the web root and beyond. So if you have an images directory in http://site.com/images, you can access it literally from /images. In PHP, you cannot do this, as it would have to go from your document root.PHP Code:header('HTTP/1.1 420 Enhance Your Calm');
Comment
-
-
Originally posted by Fou-Lu View PostYou do not need this to be relative.
HTML paths work different than PHP ones. PHP being server side can access the filesystem, while HTML only access the web root and beyond. So if you have an images directory in http://site.com/images, you can access it literally from /images. In PHP, you cannot do this, as it would have to go from your document root.
HTML can go back as many directories as needed using combinations of "../../..etc", yet PHP has no function to make it back out of a directory 1 or more times?
"$row['pic_url'];" is equal to "images/sencha/pic_name.jpg", and this cannot be changed. So I'm stuck with having the absolute URL viaPHP Code:<?php echo "<img src=\"http://www.rutholsonphoto.com" .$row['pic_url']. "\" width=\"100%\" />" ?>
Comment
-
-
Originally posted by Chris Hick View PostHave you not already applied .. to the url such as this?
PHP Code:<?php echo "<img src=\".." .$row['pic_url']. "\"/>" ?>
PHP Code:<?php echo "<img src=\"..\" .$row['pic_url']. "\"/>" ?>
Last edited by Psionicsin; Aug 29, 2011, 12:27 PM.
Comment
-
-
No they are both capable of relative. What I'm saying is, if document root is at /home/username/public_html, PHP can access anything in /home if its permissions allow, or /var or / if you can, but HTML is completely jailed to /home/username/public_html as its lowest root path.
I wouldn't replace that url at all, I just wouldn't use it. If your images directory is directly off of your public_html or whatever the document root is, you can simply use / followed by your image path. Using an absolute in HTML makes a lot of sense since you know where the root is located at all times.PHP Code:header('HTTP/1.1 420 Enhance Your Calm');
Comment
-
-
Originally posted by Psionicsin View PostOk Chris Hick, thank you for this. Since CSS that's housed in a PHP had to be formatted like field=\"value\", I assumed that the proper code should've beenPHP Code:<?php echo "<img src=\"..\" .$row['pic_url']. "\"/>" ?>
PHP Code:<?php echo "<img src=\"..\" .$row['pic_url']. ""/>" ?>
Comment
-
Comment