Hi All,
Kinda stuck here. I am trying to pull an image out of the db and resize it, then stick it back into the db. (Its a bastard solution to an ASP app problem that I have to deal with. This is the only way to do it for now).
Anyway, the code below is to take the image out, and does work if I print the image to the screen. But I am having problems saving this to a file so that I can resize it. The code does indicate success, but the file produced is 0Kb in size. I can't figure out what I am doing wrong
I my approach valid, or is there something else I should do?
TIA
Bastien
Cat, the other other white meat
Kinda stuck here. I am trying to pull an image out of the db and resize it, then stick it back into the db. (Its a bastard solution to an ASP app problem that I have to deal with. This is the only way to do it for now).
Anyway, the code below is to take the image out, and does work if I print the image to the screen. But I am having problems saving this to a file so that I can resize it. The code does indicate success, but the file produced is 0Kb in size. I can't figure out what I am doing wrong
I my approach valid, or is there something else I should do?
Code:
$sql = "select evidence from evidence where filename = '$image_name' and evidence_number = 'EV8000000'";
$results = mysql_query($sql) or die ("Can't connect to DB because ".mysql_error());
//check for results
if (($results)&&(mysql_num_rows($results)==1)){
//we have the image
while ($row=mysql_fetch_array($results)){
$img = imagecreatefromjpeg($row['evidence']);
}//end while
}//end if
//print $img;
//save the photo temporarily to the disk - delete when finished
/*$temp_image = fopen($my_image,"wb");
if (is_writable($my_image)) {
fwrite ($temp_image, $img);
}else{
echo "Cannot write to file ($filename)";
}
fclose($temp_image); */
// Let's make sure the file exists and is writable first.
if (is_writable($my_image)) {
if (!$handle = fopen($my_image, 'wb')) {
echo "Cannot open file ($my_image)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $img) === FALSE) {
echo "Cannot write to file ($my_image)";
exit;
}
echo "Success, wrote (img) to file ($my_image)";
fclose($handle);
} else {
echo "The file $my_image is not writable";
}
TIA
Bastien
Cat, the other other white meat