denewey Posted March 19, 2009 Share Posted March 19, 2009 I have a very strange thing happening on something I’m developing. I don’t know whether it’s a PHP problem or HTML or something else. It is a page for a profile of a client of the web site, which allows the client to upload a photo. I have a dummy image that’s displayed before the client uploads the image. When the client uploads the new image though, it will not display. I have verified that the image actually gets uploaded. It’s in the same directory as the dummy image. The img tag contains the same path to the new img as with the old dummy image yet the new image will not display. I’ve also verified that the database does get updated with the name of the new image. Everything seems to be as it should be, yet the image does not display. It has got me baffled! Below is the text that handles the image display: <?php $photo_display = "<img src='/photos/"; $get_photo = mysql_query("SELECT photo FROM client_profile WHERE client_id = '{$cid}'"); list ($photo) = mysql_fetch_row($get_photo); if($photo != "") { $cphoto = "photos/{$photo}"; $img_size = getimagesize($cphoto); $adjust = $img_size[0]/100; $wide = $img_size[0]/$adjust; $wpos = strpos($wide, "."); if($wpos !== false) { $wide = substr_replace($wide, "", $wpos); } $high = $img_size[1]/$adjust; $hpos = strpos($high, "."); if ($hpos !== false) { $high = substr_replace($high, "", $hpos); } $photo_display .= "{$photo}' width='{$wide}' height='{$high}' />"; //THIS ONE DOESN’T DISPLAY } else { $photo_display .= "blank_head.jpg' />"; // THIS ONE DISPLAYS ON THE PAGE } echo $photo_display; ?> Does anyone have any idea what I’m running into? ??? denewey Quote Link to comment Share on other sites More sharing options...
hellonoko Posted March 19, 2009 Share Posted March 19, 2009 First its nice if you put your code in code Hit the # button above. Next... if ($hpos !== false) { $high = substr_replace($high, "", $hpos); } $photo_display .= "{$photo}' width='{$wide}' height='{$high}' />"; //THIS ONE DOESN’T DISPLAY } else Wtf are {? if your using a $variable you need to break out of single quotes? $photo_display .= '"'.$photo.'" width="'.$wide.'" height="'.$high.'"/>'; or something. Here is how i display a image from a db on a page of mine. echo "<td><img src=../images/thumbs/t_".$row[image]." /></td>"; Quote Link to comment Share on other sites More sharing options...
denewey Posted March 19, 2009 Author Share Posted March 19, 2009 Thanks for your response. To answer your question: {} are needed for interpolating array elements and complex object references inside double quotes. For the purpose of my script they are not needed, but another developer added them in an attempt to help me sort out this problem. I tried your solution of getting everything into double quotes and that didn't work either. I did discover that on the display of the page when I right click on the image and select 'view image' I get a 403 Forbidden error - "You don't have permission to access photos/xxx.jpg on this server." Any idea what that's all about? I made sure I had the right permissions on the directories and the dummy image displays from the same directory. Is there some handling of permissions I need to do for an uploaded file? Quote Link to comment Share on other sites More sharing options...
hellonoko Posted March 19, 2009 Share Posted March 19, 2009 Should not be any odd permission things going on. Server glitch? Quote Link to comment Share on other sites More sharing options...
denewey Posted March 25, 2009 Author Share Posted March 25, 2009 It turned out that the image file itself was not being given the permissions of the directory it was uploaded to so I had to do "chmod($fpath,0644);" to change the permissions of the file after it was uploaded. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.