Page 1 of 1
Uploaded image won't display
Posted: Sat May 14, 2005 12:59 pm
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
<td width="e;80"e; valign="e;top"e; align="e;left"e;><img src="e;photos/mgr-johnsonbob.jpg"e; width="e;75"e; height="e;110"e;></td>
Posted: Sat May 14, 2005 1:27 pm
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.
Posted: Sat May 14, 2005 7:14 pm
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.
Posted: Sun May 15, 2005 12:36 pm
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();
}
Posted: Sun May 15, 2005 12:41 pm
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.
Posted: Sun May 15, 2005 12:52 pm
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.
Posted: Sun May 15, 2005 1:01 pm
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.
Posted: Sun May 15, 2005 1:10 pm
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.
Posted: Sun May 15, 2005 1:15 pm
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!
Posted: Sun May 15, 2005 1:19 pm
by cdickson
Thank you, thank you
anajesh!
I found that my chmod command was reading
when it should have been
Code: Select all
system("chmod 755 $newImagePath");
Everything is working now.
