Forum Moderators: coopster
So I used a server behavior I found in a book that works with the GD extension on a server. GD is enabled on the server I am using. However, this is not working. Here is the relevant code from the page I am using:
?php
if (!empty($row_Recordset1['imgpath'])) { ?>
<img <?php echo getDims($row_Recordset1['imgpath'], 'images/'); ?> src="<?php echo $row_Recordset1['imgpath']; ?>" alt="<?php echo $row_Recordset1['alt']; ?>" name="therPhoto" id="therPhoto"/>
<?php } ?>
AND
<?php
mysql_free_result($Recordset1);
// php code to get image dimensions dynamically
function getDims($image,$folder) {
if (!empty($folder)) {
if (strrpos($folder, '/') != strlen($folder)-1) {
$folder .= '/';
}
}
if(!empty($image) && file_exists($folder.$image)) {
$image_info = getimagesize($folder.$image);
}
$retVal = isset($image_info) ? $image_info[3] : '';
return $retVal;
}
?>
I would greatly appreciate help with this.
<?php
if (!empty($row_Recordset1[imgpath])) {
$file_name = trim($row_Recordset1[imgpath]);
list($width, $height, $type, $attr) = getimagesize("images/".$file_name);
echo "<img $attr src='images/".$file_name."' alt=\"".$row_Recordset1[alt]."\" name=\"therPhoto\" id=\"therPhoto\"/>";
}
?>
Warning: getimagesize(images/images/bbb.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home4/prescot1/public_html/prescottmentalhealth/practitioners3.php on line 237
It appears that one thing wrong (and maybe the only thing) is that the code is trying to bring the image in from images/images/bbb.jpg, rather than images/bbb.jpg, the latter being the correct path. I don't know how to fix this.
<?php
if (!empty($row_Recordset1[imgpath])) {
$file_name = trim($row_Recordset1[imgpath]);
list($width, $height, $type, $attr) = getimagesize($file_name);
echo "<img $attr src='/".$file_name."' alt=\"".$row_Recordset1[alt]."\" name=\"therPhoto\" id=\"therPhoto\"/>";
}
?>
I do have one other questions, though. Does the source code for the image need to be in any particular order for browsers? So, for example, this is the source code that is generated:
<img width="60" height="75" src='/images/carol.jpg' alt="Photo of Carol Cook, M.A., L.P.C" name="therPhoto" id="therPhoto"/>
Is that order okay?
Does the source code for the image need to be in any particular order for browsers?
While the correct answer is no, this is a good question, one I haven't seen suggested in any specifications.
In printing, we always had such rules: when specifying dimensions, specify width then height. This generated a clear industry standard when someone said 8.5 X 11.
I try to specify attributes from important to trivial, or most significant to least significant, or whatever. So
<img src="image.jpg" width="20" height="20" id="image-id" border="0" alt="alt content" title="title content">
attributes may vary with doctype . . . also "significant to least significant" can be debated ad nauseum . . . which is probably why it doesn't matter.
Whatever you do, keep it consistent, always do the same thing. There's nothing worse than setting widths for heights, heights for widths because you're trying to economize your time and expect on in a certain position when it's the other. :-)