|
Posted by bizt on 12/10/70 11:54
> ImageJPEG($thumb, $new_name);
Im getting different results in two scenarios, both not what I want.
1) When I try:
ImageJPEG($thumb, $new_name);
... and the new_name file doesnt exist, I get the following error:
Warning: imagejpeg(): Unable to open 'thumbs/image68.jpg' for writing
in /home/martyn69/public_html/photos/photos/thumb.php on line 55
2) When I try the same code but this time upload an image that has the
same name as new_name in the correct directory and then call thumb.php,
it seems to run without glitch and then redirects me in the browser to
the new_name file. Sadly, however, the new_name file has not been
overwritten and is still the file I uploaded.
Now, scenario 2) would not be ideal because the file would not exist as
that is why it is having to generate the thumb for the first time. I
just wanted to test it that way to check the behaviour.
Anyway, here is the code of thumb.php:
<?php
//this is the attribute that is used to get the filename from a db
table
$photo_id = $_GET["photo_id"];
//check if file exists, if so output that one. if not, generate new one
and (hopefully) save new thumb
$new_name = "thumbs/image" . $photo_id . ".jpg";
if (file_exists ($new_name))
{
header ("Location: " . $new_name);
}
//file does not exist so the image will need to be resized and created
else
{
include_once ("../inc/utils.php"); //contains db_conn()
$db = db_conn ("martyn69_photos");
$select = "SELECT filename FROM photos WHERE photo_id = " . $photo_id;
$result = mysql_query ($select, $db);
$img_name = mysql_result ($result, "filename");
//IMAGE GENERATE CODE
$max_width = 100;
$max_height = 100;
$size = GetImageSize ($img_name);
$width_ratio = ($size[0] / $max_width);
$height_ratio = ($size[1] / $max_height);
if ($width_ratio >= $height_ratio)
{
$ratio = $width_ratio;
}
else
{
$ratio = $height_ratio;
}
$new_width = ($size[0] / $ratio);
$new_height = ($size[1] / $ratio);
$src_img = ImageCreateFromJPEG ($img_name);
$thumb = ImageCreateTrueColor ($new_width, $new_height);
ImageCopyResampled ($thumb, $src_img, 0, 0, 0, 0, ($new_width-1),
($new_height-1), $size[0], $size[1]);
//header ("Content-type: image/jpeg");
//ImageJPEG ($thumb);
ImageJPEG ($thumb, $new_name);
//destroy
ImageDestroy ($src_img);
ImageDestroy ($thumb);
}
?>
I have ensured permissions are set to 777. I have in the past had to
contact my web host guys to allow me to write to dir even tho they were
set at 777, is this the case here or is my code faulty? Cheers
Burnsy
Navigation:
[Reply to this message]
|