Reputation: 4193
I have the following php code, which has been snipped for brevity. I am having trouble with the code after $lastImg is declared, specifically size never seems to get assigned any value, and the hence outputwidth and outputheight remain blank. I have been unable to spot the cause of this.
pic_url is just a string in the database, and definitely points to a valid image. When I run my page without the code to resize, the image is displayed perfectly.
<?php
header("Content-Type: text/html; charset=utf-8");
if (isset($_GET["cmd"]))
$cmd = $_GET["cmd"];
else
die("You should have a 'cmd' parameter in your URL");
$pk = $_GET["pk"];
$con = mysql_connect("localhost", "someuser", "notreal");
if(!$con)
{
die('Connection failed because of' . mysql_error());
}
mysql_query('SET NAMES utf8');
mysql_select_db("somedb",$con);
if($cmd == "GetAuctionData")
{
$sql="SELECT * FROM AUCTIONS WHERE ARTICLE_NO ='$pk'";
$sql2="SELECT ARTICLE_DESC FROM AUCTIONS WHERE ARTICLE_NO ='$pk'";
$htmlset = mysql_query($sql2);
$row2 = mysql_fetch_array($htmlset);
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$columns = array('FINISHED', 'WATCH', 'PRIVATE_AUCTION', 'REVISED', 'PAYPAL_ACCEPT', 'PRE_TERMINATED', 'PIC_XXL', 'PIC_DIASHOW');
foreach($columns as $column)
{
$$column = $row[$column] ? 'YES' : 'NO';
}
$lastImg = $row['PIC_URL'];
$maxWidth = 250;
$maxHeight = 300;
$size = getimagesize($_SERVER['DOCUMENT_ROOT'] . $lastImg);
var_dump($size);
echo "SIZE = ".$size."";
if ($size) {
$imageWidth = $size[0];
$imageHeight = $size[1];
$wRatio = $imageWidth / $maxWidth;
$hRatio = $imageHeight / $maxHeight;
$maxRatio = max($wRatio, $hRatio);
else {
die(print_r(error_get_last())); }
else if ($maxRatio > 1) {
$outputWidth = $imageWidth / $maxRatio;
$outputHeight = $imageHeight / $maxRatio;
} else {
$outputWidth = $imageWidth;
$outputHeight = $imageHeight;
}
}
echo "<h1>".$row['ARTICLE_NAME']."</h1>
<div id='rightlayer'>
<img src='".$lastImg."' width='".$outputWidth."' height='".$outputHeight."'>
</div>";
}
}
mysql_free_result($result);
Upvotes: 0
Views: 217
Reputation: 123453
You have a few things that conflict with each other:
$size = getimagesize($lastImg);
echo "<img src='".$lastImg."' ...>"
getimagesize
expects a filename while <img>
expects a URL.
You might try something like this:
$root = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['SCRIPT_FILENAME']);
$size = getimagesize($root . $lastImg);
[EDIT] Sorry. DOCUMENT_ROOT
wasn't right.
Upvotes: 0
Reputation: 6494
First, to get the right error message, change your code to:
$size = getimagesize($lastImg);
echo "SIZE = ".$size."";
if ($size) {
$imageWidth = $size[0];
$imageHeight = $size[1];
$wRatio = $imageWidth / $maxWidth;
$hRatio = $imageHeight / $maxHeight;
$maxRatio = max($wRatio, $hRatio);
if ($maxRatio > 1) {
$outputWidth = $imageWidth / $maxRatio;
$outputHeight = $imageHeight / $maxRatio;
} else {
$outputWidth = $imageWidth;
$outputHeight = $imageHeight;
}
} else {
die(print_r(error_get_last()));
}
After that, we can look at the error and try to investigate further.
Upvotes: 0
Reputation: 23
Try:
$lastImg = $row['PIC_URL'];
var_dump($row);
die();
to see if you have anything in $row['PIC_URL'].
Upvotes: 0
Reputation: 69991
1st. do a
print_r($row)
just below your
while ($row = mysql_fetch_array($result))
And see if the array PIC_URL is set there
2nd you really should do a safe Query.
$sql="SELECT * FROM AUCTIONS WHERE ARTICLE_NO ='$pk'";
Should be
$sql = sprintf("SELECT * FROM AUCTIONS WHERE ARTICLE_NO = %d", mysql_real_escape_string($pk));
Same with the other SQL query.
Upvotes: 0