Whats wrong with this code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
definewebsites
Forum Newbie
Posts: 19
Joined: Thu May 01, 2008 9:51 pm

Whats wrong with this code

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Whats wrong with this code

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Whats wrong with this code

Post 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.
definewebsites
Forum Newbie
Posts: 19
Joined: Thu May 01, 2008 9:51 pm

Re: Whats wrong with this code

Post 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
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: Whats wrong with this code

Post 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
definewebsites
Forum Newbie
Posts: 19
Joined: Thu May 01, 2008 9:51 pm

Re: Whats wrong with this code

Post 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..
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Whats wrong with this code

Post 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" />';
 
remyx187
Forum Newbie
Posts: 8
Joined: Tue Apr 29, 2008 11:49 am

Re: Whats wrong with this code

Post 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.
definewebsites
Forum Newbie
Posts: 19
Joined: Thu May 01, 2008 9:51 pm

Re: Whats wrong with this code

Post 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
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: Whats wrong with this code

Post 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 :)
Post Reply