Question:
PHP image resize Script error?
Matthew T
2013-01-30 13:38:16 UTC
I have a PHP script that takes a image on submission of a form, takes a copy of the orginal file, resizes it and is renamed.
The script all works and the copies are made accept after the form is submitted I get the following error message even though the script works and copies are created, any ideas?

Error Message: Warning: imagejpeg() [function.imagejpeg]: Unable to open 'Members/118/' for writing: Is a directory in /home/mattthor/public_html/fitnetwork.co.uk/PHPScripts/ak_php_img_lib_1.0.php on line 26

Script in question:


// ----------------------- RESIZE FUNCTION -----------------------
// Function for resizing any jpg, gif, or png image files
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);

$img = "";
$ext = strtolower($ext);
if ($ext == "gif"){
$img = imagecreatefromgif($target);
} else if($ext =="png"){
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);


imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
if ($ext == "gif"){
$img = imagegif($tci, $newcopy);
} else if($ext =="png"){
$img = imagepng($tci, $newcopy);
} else {
$img = imagejpeg($tci, $newcopy, 84);
}

}

?>
Three answers:
Huzoor
2013-02-03 03:07:38 UTC
With your image resizing you will need to write to the directory where the image resides. If its permissions do not allow this, then you will get the error you are getting, in which case you have some other choices (only relevant if this functionality is new ... if it has worked in the past it may be a problem with just one corrupt image):



1) rearrange the place where all images reside to a directory where you don't mind there being a fairly open permission regime (maybe not a great idea as far as security goes)

2) use a directory with write permissions only for the writing place, but leave the reading place as is (this might have repercussions in other parts of your website with respect to where you look for images)

3) maybe this is functionality to sit behind a password protected image directory (some web servers allow password protected directories)
?
2013-01-30 13:47:14 UTC
With your image resizer you will need to write to the directory where the image resides. If its permissions do not allow this, then you will get the error you are getting, in which case you have some other choices (only relevant if this functionality is new ... if it has worked in the past it may be a problem with just one corrupt image):



1) rearrange the place where all images reside to a directory where you don't mind there being a fairly open permission regime (maybe not a great idea as far as security goes)

2) use a directory with write permissions only for the writing place, but leave the reading place as is (this might have repercussions in other parts of your website with respect to where you look for images)

3) maybe this is functionality to sit behind a password protected image directory (some web servers allow password protected directories)
Heysql
2013-01-30 13:41:34 UTC
im guessing that the imagejpg function isn't working and what you tested isn't a jpeg.



Nothing seems wrong with the code you provided. Its most likely the function itself.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...