I've had a look through several of the related questions and just can't seem to see the issue!
the following two functions are within my function include file and for some reason I cannot seem to get the check_orientation function to return scale to the display_months_news function.
I'm fairly sure I'm just missing something really obviously.
the display_news function
function display_months_news()
{
//header('Content-type: image/jpeg');
$year = date("y");
$year = "20" .$year;
$month = date("m");
if ($month) {
switch ($month){
case "01": $month = "January"; break;
case "02": $month = "February"; break;
case "03": $month = "March"; break;
case "04": $month = "April"; break;
case "05": $month = "May"; break;
case "06": $month = "June"; break;
case "07": $month = "July"; break;
case "08": $month = "August"; break;
case "09": $month = "September"; break;
case "10": $month = "October"; break;
case "11": $month = "November"; break;
case "12": $month = "December"; break;
}
} else {
echo '<p>The date field is empty.</p>';
}
$nowdate = $month." ".$year;
$result = mysql_query("SELECT * FROM news ORDER BY sqldate DESC LIMIT 6") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
global $imgurl;
$imgurl = $row['img1'];
check_orientation4($imgurl);
$comcount = comment_count($row['nid']);
if ($comcount == NULL) {$comcount = 0;}
echo '<div class="news-preview-container">';
echo '<div class="news-preview-container-date">';
echo "<P>" .$row['mmonth']. " ".$row['dday']. ", " .$row['yyear']. "</p><BR>";
echo '</div>';
echo '<div class="news-preview-container-title">';
echo "<p><a href='article.php?id=" .$row['nid']."'>" .$row['title']."</a></p><BR>";
ech开发者_StackOverflow社区o '</div>';
echo '<div class="news-preview-container-inner">';
echo '<div class="news-preview-container-text">';
echo '<p>'.ShortenText($row['body']).'</p>';
echo '</div>';
echo '<div class="news-preview-container-image"><img src="'.$imgurl.'"'.$scale.'"></div><BR></div>';
echo '<div class="news-preview-container-bottombar">Posted in '.$row[tag].' / '.$comcount.' Comments</div>';
echo '</div>';
}
}
and the check_orientation function
function check_orientation4($imgurls){
if ($imgurls == NULL){ echo ""; }
else {
$imgurlshrunk = NULL;
$maxsize = 120;
$filename = NULL;
$height = NULL;
$width = NULL;
$scale = NULL;
$imgurlshrunk = $imgurls;
$filename = basename($imgurlshrunk);
$filename = "admin/uploads/" . $filename;
list($width,$height,$type,$attr) = getimagesize("$filename");
$wRatio = $maxsize / $width;
$hRatio= $maxsize / $height;
global $scale;
if ( ($width <= $maxsize) && ($height <= $maxsize))
{
$scale = "";
return $scale;
}
elseif ( ($wRatio * $height) < $maxsize)
{
$scale = "width = '100%'";
return $scale;
}
elseif ($height == NULL)
{
echo "empty height";
}
else
{
global $height;
$scale = "height = '100%'";
return $scale;
} }}
Thanks in advance to whoever points out the silly mistake i'm missing!
You don't store the result of check_orientation4($imgurl);
anywhere. Try changing that line to this:
$scale = check_orientation4($imgurl);
You aren't doing anything with the return value of check_orientation4
You're not assigning the return value of check_orientation4 to anything.
check_orientation4($imgurl);
should be
$scale = check_orientation4($imgurl);
Shouldn't you be returning scale into a variable of some kind? Right now you're just running the function. You should do something like:
$toScale = check_orientation4($imgurl);
Because you're discarding the return value from check_orientation4, perhaps?
精彩评论