IronWarrior Posted August 26, 2008 Share Posted August 26, 2008 Warning: imagejpeg() [function.imagejpeg]: Unable to open 'images/1219763756small.jpg' for writing: Permission denied in C:\AppServ\www\tanksforsale\submitAnItem.php on line 91 Here is my code; this error only occurs some times, I think its because I am trying to resize and add text to the image in quick succesion, anyone got a fix. Here is my code: <?php error_reporting(E_ALL); if (isset($_POST["validTransaction"])) { $vehicleName = $_POST["vehicleName"]; $vehicleDescription = $_POST["vehicleDescription"]; $vehiclePrice = $_POST["vehiclePrice"]; $vehicleType = $_POST["vehicleType"]; $vehicleCategory = $_POST["vehicleCategory"]; $trimmedVehicleName = str_replace(" ","",$vehicleName); $folderLocation = "images"; $currentTime = time(); //Checking if all fields are present if ($vehicleName == "" || $vehicleDescription == "" || $vehiclePrice == "" || $vehicleType == "" || $vehicleCategory == "") { echo "Not all infomation has been completed, please use the return button to re-submit the infomation"; $error = true; } //If all fields have been completed, then continue. else { //Adding the item details to the database mysql_query("INSERT INTO vehiclesforsale (vehicleName, vehicleDescription, vehiclePrice, vehicleType, vehicleCategory, timeAdded) VALUES ('$vehicleName', '$vehicleDescription', '$vehiclePrice', '$vehicleType', '$vehicleCategory', '$currentTime')"); $result = mysql_query("SELECT * FROM vehiclesforsale WHERE vehicleName='$vehicleName' AND timeAdded='$currentTime'"); $row = mysql_fetch_array($result); $linkedItemID = $row['vehicleID']; // Multiple Image Loop for ($index=0;$index<4;$index++) { $currentTime = $currentTime + $index; $newName = $folderLocation."/".$currentTime.".jpg"; // Checking if an image has been uploaded if (is_uploaded_file($_FILES['imgfile']['tmp_name'][$index])) { //Copying the file to the directory if (!copy($_FILES['imgfile']['tmp_name'][$index], $newName)) { // Error message for file upload print "Error Uploading File."; exit(); } //If the copy is sucessful else { // Success message for file upload. echo "We have uploaded file number: $index <br />"; //Adding the image infomation to the database mysql_query("INSERT INTO images (imageID, linkedItem, uploaderID) VALUES ($currentTime, '$linkedItemID', '-')"); // Creating the Small Image // The image to resize $sourceImage = imagecreatefromjpeg($newName); // Capture the original size of the uploaded image list($width,$height)=getimagesize($newName); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=300; $newheight=($height/$width)*300; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$sourceImage,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $newNameSmall =$folderLocation."/".$currentTime."small.jpg"; imagejpeg($tmp,$newNameSmall,100); imagedestroy($sourceImage); // Watermarking the small image $stringToWatermark = "www.tanksforsale.co.uk"; $font = 4; $width = ImageFontWidth($font)* strlen($stringToWatermark) ; $height = ImageFontHeight($font) ; $im = ImageCreateFromjpeg($newNameSmall); $x=imagesx($im)-$width ; $y=imagesy($im)-$height; $background_color = imagecolorallocate ($im, 255, 255, 255); //white background $text_color = imagecolorallocate ($im, 255, 250,250);//black text imagestring ($im, $font, $x, $y, $stringToWatermark, $text_color); imagejpeg ($im,$newNameSmall); // Creating the preview Image // The image to resize $sourceImage = imagecreatefromjpeg($newName); // Capture the original size of the uploaded image list($width,$height)=getimagesize($newName); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=210; $newheight=($height/$width)*210; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$sourceImage,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $newNamePreview =$folderLocation."/".$currentTime."preview.jpg"; imagejpeg($tmp,$newNamePreview,100); imagedestroy($sourceImage); // Watermarking the Preview image $stringToWatermark = "www.tanksforsale.co.uk"; $font = 4; $width = ImageFontWidth($font)* strlen($stringToWatermark) ; $height = ImageFontHeight($font) ; $im = ImageCreateFromjpeg($newNamePreview); $x=imagesx($im)-$width ; $y=imagesy($im)-$height; $background_color = imagecolorallocate ($im, 255, 255, 255); //white background $text_color = imagecolorallocate ($im, 255, 250,250);//black text imagestring ($im, $font, $x, $y, $stringToWatermark, $text_color); imagejpeg ($im,$newNamePreview); } } } } } else { echo "Invalid Transaction"; } ?> Link to comment https://forums.phpfreaks.com/topic/121410-imagejpeg-function-error/ Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Read the error, you don't have permissions. You need to make sure that you have at least 644 permissions on the file in question. EDIT: You're on Windows (just saw the file path of the error). I'll let a Windows user help with this one. >_> Link to comment https://forums.phpfreaks.com/topic/121410-imagejpeg-function-error/#findComment-626045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.