Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

How do I replace missing images? URGENT!

images php coding issues or problems here.

Moderators: macek, egami, gesf

How do I replace missing images? URGENT!

Postby ThprAdmin » Fri Feb 03, 2012 1:38 am

Hi I recently made the switch from cgi to php and need some help. I manage a member based website and with profiles and I used to have a bit of code that would automatically check if a member had uploaded a photo and if they had not, it would display our default no-pic image. However that bit of code does not seem to work in php.

My old cgi code which dynamically changes the name of the image to look for:

open (PIC, "/pathto/$productId.jpg");
$whatever = @pic;
$picstatus = "<img src=\"/pathto/no-pic.jpg\" width=\"232\" border=\"0\">";
if ($whatever ne "0"){
$picstatus = "<img src=\"/pathto/$productId.jpg\" width=\"232\" border=\"0\">";

I found this piece pf php code that should have worked. But does not. the php does not want to see the dynamically created file name. WHY?? Eveytime I try using it this in various forms it always displays the no-pic result. When I checked to see what file it was checking for, it echoed the variable and not the actual image file ie: <?php echo $row->username;?>.jpg, which clearly is not the name of the file. Can some one modify my old cold to work for php or tell me how to get this new bit of code to work dynamically. Thank you very much.

The new php code which should dynamically changes the name of the image to look for but does not.

$filename = '/pathto/<?php echo $row->username;?>.jpg';
if (file_exists($filename)) {
echo '<img src="/pathto/<?php echo $row->username;?>.jpg" alt="<?php echo $row->username;?>">';
} else {
echo '<img src="/pathto/no-pic.png" alt="no photo">';
New php-forum User
New php-forum User
Posts: 2
Joined: Fri Feb 03, 2012 12:47 am

Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.