Uploaded image won't display

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
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Uploaded image won't display

Post by cdickson »

Now my image won't display. While I have worked on a number of databases before, this is my first time working with uploading and displaying images.

The code that is generated appears to be correct, and the photo is uploading to the server properly, but instead of the image I see a missing image icon. If I try to save the photo from the web page, I get an error message that it isn't there, even though the path to the image is correct and the file is on the server.:?:

PHP CODE TO SHOW IMAGE:

Code: Select all

echo("<td width=\"80\" valign=\"top\" align=\"left\">");
	
	if (empty($row["StaffPhoto"])){
		echo ("");
			} else {
		echo ("<img src=\"photos/{$row['StaffPhoto']}\" width=\"75\" height=\"110\">"); 
		} 
	echo("</td>");


GENERATED CODE:

Code: Select all

&lt;td width=&quote;80&quote; valign=&quote;top&quote; align=&quote;left&quote;&gt;&lt;img src=&quote;photos/mgr-johnsonbob.jpg&quote; width=&quote;75&quote; height=&quote;110&quote;&gt;&lt;/td&gt;
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

This must be a relative path problem.
photos/mgr-johnsonbob.jpg may be there - The script where you have this php code must be in the directory right above photos.

[current directory]
|
|-photos

This cannot be a PHP / MySQL problem because the HTML code is generated correctly.
Please check the relative paths.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I would use a URL to see if this corrects the problem. http://www.domain.com/photos/pic.jpg in your HTML.
If it does fix the problem, then your path is wrong.. as stated above.
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Thanks for the suggestions. Actually I did try using the URL before I posted here. I tried again just now and am still getting the same results.

At first I thought that it might be because the images were in a password protected subdirectory, so I moved it out of there. The full URL to the image is still generated properly in the HTML code (http://www.mydomain.com/staff/photo.jpg), the file is in the correct directory, but I'm still getting the icon instead of the image.

The script is set up to chmod the files to 755 when they are uploaded, and I have verified that this is happening.

Could there be something else in the upload code that is creating the issue? The full code for uploading is:

Code: Select all

if($HTTP_POST_VARS['Upload'] == "Upload"){
}
 
if($_POST['Upload'] == "Upload"){
 
$originalImageFileName = $_FILES['StaffPhoto']['name'];
$tempImageFileName = $_FILES['StaffPhoto']['tmp_name'];
 
$siteRoot = $_SERVER["DOCUMENT_ROOT"];
$uploadDir = $siteRoot . "/home/www/www/staffadmin/";
$newImagePath = "/home/www/www/staff/" . $originalImageFileName;
 
umask(0);
move_uploaded_file($tempImageFileName, $newImagePath);
system("chmod 755 $newPath");
 
$query = "INSERT INTO staff (
	Category, List_no, StaffName, StaffTitle, Extension, StaffPhoto) 
	VALUES ('" . $_POST['Category'] . "', '" . $_POST['List_no'] . "', '" . $_POST['StaffName'] . "', '" . $_POST['StaffTitle'] . "', '" . $_POST['Extension'] . "', '" . $_FILES['StaffPhoto']['name'] . "')";

$result = mysql_query($query);
$lastInserted = mysql_insert_id();
}
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Dont know what 755 is - just check if its readable using some standard ftp program - or log in IE and right-click and check if read permission is set.
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

I can see the image file using FTP - that is how I verified that the file got uploaded to the correct subdirectory.

When I go into IE and check the missing image properties, it displays the correct protocol, URL and dimensions of the image. The type, size and created/modified dates are all listed as not available.

Also, if I create a blank HTML page and link to the same image using the full URL, the image doesn't display properly.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I meant - in IE log in ftp - like
ftp://username:password@domainname.com
And right-click the file and check the properties - just like explorer.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Sounds like a permissions problem to me. Although the sticky bit 755 is enough, I'd make sure the owner/group is readable by the user running the webserver. And the directory it is in.
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Sorry! I was unaware of this process. When I check the photo this way the permissions are:

Owner - RW
Group
All Users

so this is apparently where the problem is. In my script where I chmod to 755, this is language for use on a Unix server and 755 means:

Owner RWE
Group RE
All RE

It appears that this permissions command isn't working, so I need to figure out why.

Thanks!
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Thank you, thank you anajesh!

I found that my chmod command was reading

Code: Select all

system("chmod 755 $newPath");
when it should have been

Code: Select all

system("chmod 755 $newImagePath");
Everything is working now. :D
Post Reply