I am building an object oriented form class to speed some of my development projects, but am running into difficulty when migrating over my image upload -> thumbnail generator function. I am getting the error:
"Warning: Unable to create './img/user/P1010024.JPG': Permission denied in c:\inetpub\wwwroot\vendor\obj\form.php on line 271"
Being denied permission to write the file to disk on the initial upload, before generating the thumbnail. I have checked my directory permissions and they seem correct. I feel like I am overlooking something small here which hopefully someone else can catch. A working example of the problem is available <a href="http://www.vortexstudio.com/vendor/test.php" target="_blank">here</a> though that server doesn't have the GD library. Here is the function code itself, the error is coming from this line:
"copy($imagePointer, $tempDir);"
function createJPEGThumbnail($imagePointer, $saveDir, $thumbnailWidth, $fullSizeWidth) {
$imageURL = $this->values["image"];
$imageName = $this->parseLast($imageURL, "\\");
$imageExtension = $this->parseLast($imageName, ".");
// check for filename existance
while(file_exists("$saveDir/$imageName")) {
$imageName = "1" . $imageName;
}
// copy file to local directory
$tempDir = $saveDir . "/" . $imageName;
print("$tempDir<br>");
copy($imagePointer, $tempDir);
// create an image object from the existing file
$imIn = ImageCreatefromJPEG($tempDir);
// get size of original image
$size = GetImageSize($tempDir);
// calculate size for new thumbnail canvas
if($size[0] > $thumbnailWidth) {
$imOutWidthThumb = $thumbnailWidth;
$resizeFactor = $thumbnailWidth / $size[0];
$imOutHeightThumb = $resizeFactor * $size[1];
} else {
$imOutWidthThumb = $size[0];
$imOutHeightThumb = $size[1];
}
// calculate size for new fullsize canvas
if($size[0] > $fullSizeWidth) {
$imOutWidthFull = $fullSizeWidth;
$resizeFactor = $fullSizeWidth / $size[0];
$imOutHeightFull = $resizeFactor * $size[1];
} else {
$imOutWidthFull = $size[0];
$imOutHeightFull = $size[1];
}
// create the blank canvas
$imOutThumb = ImageCreate($imOutWidthThumb, $imOutHeightThumb);
$imOutFull = ImageCreate($imOutWidthFull, $imOutHeightFull);
// copy the original image to the thumbnail
ImageCopyResized($imOutThumb, $imIn, 0, 0, 0, 0, $imOutWidthThumb, $imOutHeightThumb, $size[0], $size[1]);
// copy the original image to the fullsize
ImageCopyResized($imOutFull, $imIn, 0, 0, 0, 0, $imOutWidthFull, $imOutHeightFull, $size[0], $size[1]);
$thumbnail = "thumbnail_" . $imageName;
$fullSize = "full_" . $imageName;
// output the image and destroy it
ImageJPEG($imOutThumb, "$saveDir/thumbnail/$thumbnail", 100);
ImageJPEG($imOutFull, "$saveDir/fullsize/$fullSize", 100);
ImageDestroy($imIn);
ImageDestroy($imOutThumb);
ImageDestroy($imOutFull);
unlink($tempDir);
}