Uploading Image (Make Thumbnail)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Uploading Image (Make Thumbnail)

Post by AliasBDI »

I am getting this error:
Warning: imagejpeg() [function.imagejpeg]: Unable to open '../eControl_repository/File/Accounts/thumbs/Jacob_1038.jpg' for writing in /mnt/Target01/331444/331704/www.lukatchoo.com/web/content/create/in ... uilder.php on line 206
Can anyone tell me what this means? Here is my code:

Code: Select all

$filename = $_FILES['acctImgPath']['name'];
		$temporary_name = $_FILES['acctImgPath']['tmp_name'];
		$mimetype = $_FILES['acctImgPath']['type'];
		$filesize = $_FILES['acctImgPath']['size'];
		switch($mimetype) {
			case "image/jpg":
				$i = imagecreatefromjpeg($temporary_name);
				$typeID = 1;
				break;
			case "image/jpeg":
				$i = imagecreatefromjpeg($temporary_name);
				$typeID = 1;
				break;
			case "image/pjpeg": //IE's weird jpeg MIME type
				$i = imagecreatefromjpeg($temporary_name);
				$typeID = 1;
				break;
			case "image/gif":
				$i = imagecreatefromgif($temporary_name);
				$typeID = 2;
				break;
		}
		unlink($temporary_name);
		// upload image
		if ($typeID==1) { // is jpg
			imagejpeg($i,"../eControl_repository/File/Accounts/".$acctFirstName."_".$newID.".jpg",80);
		} elseif ($typeID==2) {
			imagegif($i,"../eControl_repository/File/Accounts/".$acctFirstName."_".$newID.".gif");
		}
		$dest_x = 50;
		$dest_y = 50;
		if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
			if (imagesx($i) >= imagesy($i)) {
				$thumb_x = $dest_x;
				$thumb_y = imagesy($i)*($dest_x/imagesx($i));
			} else {
				$thumb_x = imagesx($i)*($dest_y/imagesy($i));
				$thumb_y = $dest_y;
			}
		} else {
			$thumb_x = imagesx($i);
			$thumb_y = imagesy($i);
		}
		$thumb = imagecreate($thumb_x,$thumb_y);
		imagecopyresampled($thumb, $i,0, 0, 0, 0, $thumb_x, $thumb_y, imagesx($i), imagesy($i));
		if ($typeID==1) { // is jpg
			imagejpeg($thumb, "../eControl_repository/File/Accounts/thumbs/".$acctFirstName."_".$newID.".jpg", 80);
		} elseif ($typeID==2) { // is gif
			imagegif($thumb, "../eControl_repository/File/Accounts/thumbs/".$acctFirstName."_".$newID.".jpg");
		}
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

This is asked about once a week here (search before posting!) - touch() the file first.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Or permissions. Check that the user PHP is running as can write to that file.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply