Hi,
I have a file upload problem, but I don't think it's a permission thing (if only, that would be simple!).
I have written a resizing method for a class I'm working on, and it always fails on the imageJpeg() at the end of the method. This is the error I get...
imagejpeg(): Unable to open '/Library/WebServer/Documents/my_site/lib/products/2_big_me.jpg' for writing in /Library/WebServer/Documents/my_site/lib/classes/class.products.php on line 132
Now, here's the strange bit, if I call my method and just use move_uploaded_file() then the image is saved correctly, soI know it's not the permissions, could someone have a little lookat my method and let me know if there's anything wrong with it please
// $ID is an integer used for naming purposes
// $aImage is an array, it's basically a copy of $_FILES["image"]
// BASE_DIR is a constant var and holds, yep you guessed it, the base dir of the site!
// IMGMAXHEIGHT & IMGMAXWIDTH are also constants used for resizing purposes
function storeBigImage($ID, $aImage){
________// create filenames
________fopen($aImage['name'], 'r');
________$aNewImage['real_name'] = $aImage['name'];
________$aNewImage['new_name'] = $ID . '_' . 'big' . '_' . $aNewImage['real_name'];
________$aNewImage['image_loc'] = BASE_DIR . '_lib/_products/' .__$aNewImage['new_name'];
_________
________// copy original image
________$aNewImage['original_image'] = ImageCreateFromJpeg($aImage['tmp_name']);
________$aNewImage['sizes'] = getimagesize($aImage['tmp_name']);
________$aNewImage['width'] = $aNewImage['sizes'][0];
________$aNewImage['height'] = $aNewImage['sizes'][0];
________
________if($aNewImage['width'] >= IMGMAXWIDTH || $aNewImage['height'] >= IMGMAXHEIGHT){
____________
____________// calculate ratios
____________$iRatio_w = IMGMAXWIDTH / $aNewImage['width'];
____________$iRatio_h = IMGMAXHEIGHT / $aNewImage['height'];
____________$iRatio = $iRatio_w < $iRatio_h ? $iRatio_w:$iRatio_h;
____________
____________// calculate new dimensions
____________$aNewImage['new_width'] = $aNewImage['width'] * $iRatio;
____________$aNewImage['new_height'] = $aNewImage['height'] * $iRatio;
____________
____________// save resized image
____________$aNewImage['new_image'] = ImageCreateTrueColor($aNewImage['new_width'], $aNewImage['new_height']);
____________ImageCopyResized($aNewImage['new_image'], ImageCreateFromJpeg($aImage['tmp_name']), 0, 0, 0, 0, $aNewImage['new_width'], $aNewImage['new_height'], $aNewImage['width'], $aNewImage['height']);
____________//ImageJpeg($aNewImage['new_image'], $aNewImage['image_loc']);
____________ImageJpeg($aNewImage['original_image'], $aNewImage['image_loc']);
________
________} else {
________
____________// save original image
____________//ImageJpeg($aImage['tmp_name'], $aNewImage['image_loc']);
____________ImageJpeg($aNewImage['original_image'], $aNewImage['image_loc']);
____________//ImageJpeg($this->aArgs['Image']['tmp_name'], $aNewImage['image_loc']);
________}
____}
I have ftp'd into my local server and the folder in question is set at 777, and like I said it works fine if I don't use this class
Any ideas ??
Thanks,
Jon