Page 1 of 1

Whats wrong with this code

Posted: Thu May 01, 2008 9:51 pm
by definewebsites
Hi there,

I am developing a content management system, and I have some details stored in a mysql database. I am trying to retrieve an image whose path is stored in the database.

I obtained the path using the following:

Code: Select all

 
$uploadDir = $_SERVER['DOCUMENT_ROOT'] .  "/images/portfolio/";
 
and after retrieving the details from the database, I am trying to display it using the below as part of a table:

Code: Select all

 
echo "<td rowspan=\"3\"><img src=\" ".$content . "\"/></td>";
 
but the image is not showing. I would appreciate it if someone could point me in the right direction as I have been staring at this for the past 30 minutes without a clue.. :(

Thanks

Re: Whats wrong with this code

Posted: Fri May 02, 2008 12:43 am
by Zoxive

Code: Select all

echo "<td rowspan=\"3\"><img src=\" " . $uploadDir . $content . "\"/></td>";
A bit difficult trying to understand your problem. Your current output of this would help, and some more information as well.

Re: Whats wrong with this code

Posted: Fri May 02, 2008 6:31 am
by aceconcepts
From your second segment of code you would simply be outputting $content.

What is the value of $content? If $content is simply the file name then Zoxive has helped you out already.

Re: Whats wrong with this code

Posted: Fri May 02, 2008 7:01 am
by definewebsites
Hi guys,

Thanks for the responses. Well, the "$content" contains the full path to the image, which looks like this:

/home/content/k/a/b/user/html/images/portfolio/myImage.jpg

Any suggestions?

Thanks

Re: Whats wrong with this code

Posted: Fri May 02, 2008 7:43 am
by highjo
Hey! don't know on what u are developing but what i do to reference my root is this

Code: Select all

$uploaddir = "./images/portfolio";
the dot means the root and if you change your server name or something has changed then there would not be much problem.
Somebody correct me if i'm wrong

Re: Whats wrong with this code

Posted: Fri May 02, 2008 8:05 am
by definewebsites
Hi,

I tried your method, but just got an error stating that no such directory exists, as the dot does not seem to take it to the document root of the server.

I should think that since I have the image path stored as the complete path on the server it should show the image when I use it as a source, but do not understand why it is not working.

Thanks for all the help..

Re: Whats wrong with this code

Posted: Fri May 02, 2008 8:07 am
by aceconcepts
Have you tried using the literal absolute path in the img src to see if your syntax is right?

Code: Select all

 
echo'<img src="/home/content/k/a/b/user/html/images/portfolio/myImage.jpg" />';
 

Re: Whats wrong with this code

Posted: Fri May 02, 2008 10:56 am
by remyx187
All in all this should work (ideally):

Code: Select all

$uploadDir = "/home/content/k/a/b/user/html/images/portfolio/";
echo "<td rowspan=\"3\"><img src=\"" . $uploadDir . $content . "\"/></td>";
a fusion of previous posts.

if its not that, double check your paths, make sure the images exist, and the $content variable acquires the right image names.

Re: Whats wrong with this code

Posted: Fri May 02, 2008 6:45 pm
by definewebsites
I'd like to thank all of you for your assistance.

Well, I did try using the absolute URL to load the image, but that did not work so I take it that the setup of the server my website is not compatible with loading content via that path, so I developed a workaround.

I simply just extracted a substring of the full path that contains the end bit: /images/portfolio/myImage.jpg , and appended the starting URL to it. Its now working perfectly. :)

I do appreciate all the assistance.

Cheerio

Re: Whats wrong with this code

Posted: Sat May 03, 2008 2:20 am
by Mordred
Err, people, that's not how HTML works. Back to first grade all of you, except the OP who got it right in the end :)