punstc Posted June 24, 2008 Share Posted June 24, 2008 I'm really new at php and trying to figure out some of the image resizing things. but i'm having problems. I'm working with some reference that my lab instructor gave me but trying to combine it with my own code I'm running into problems. It keeps giving me this error Warning: move_uploaded_file(../gallery_images/large/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/2008/03/jchamberlain/public_html/wpr/final_project/admin/gallery2.php on line 21 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpl9AFmE' to '../gallery_images/large/' in /home/2008/03/jchamberlain/public_html/wpr/final_project/admin/gallery2.php on line 21 I could really use some help on this heres my code <?php $this_file = basename($_SERVER['PHP_SELF']); if(empty($_POST)){ $status = ' '; } else { $desc = $_POST['desc']; $destination = '../gallery_images/large/'; $large = $_FILES['large']['name']; $large_tmp = $_FILES['large']['tmp_name']; $error_list = array(); if(empty($large)){ $error_list[] = 'Image'; } if(empty($desc) OR ($desc == 'Description')){ $error_list[] = 'Description'; } else { if(move_uploaded_file($large_tmp, $destination)){ $image_path = "../gallery_images/large/$large"; // Gets temorary image name from the server $dest_path = "../gallery_images/thumb/"; // Sets path to thumbnail images $max_width = 200; $max_height = 150; $size = GetImageSize($image_path); $width = $size[0]; $height = $size[1]; $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if(($width <= $max_width) && ($height <= $max_height)){ $new_width = $width; $new_height = $height; } elseif(($x_ratio * $height) < $max_height){ $new_height = ceil($x_ratio * $height); $new_width = $max_width; } else{ $new_width = ceil($y_ratio * $width); $new_height = $max_height; } $src = imagecreatefromjpeg($image_path); $dst = imagecreatetruecolor($new_width,$new_height); imagecopyresized($dst, $src, 0, 0, 0, 0, $new_width,$new_height,$width,$height); imagejpeg($dst,"$dest_path"."$large", 90); $thumb = "$dest_path"."$large"; imagedestroy($src); imagedestroy($dst); $status = "<p>The image \". $image. \" has been uploaded!</p>"; $sql = "INSERT INTO jchamb_gallery SET large='$large', thumb='$thumb' desc='$desc'"; $result = mysql_query($sql); } else{ $status = "<p>There was an error uploading the image, please try again.</p>"; } } } if(count($error_list) > 0) { $status = "<p>You did not provide a(n):</p>\n"; foreach($error_list as $error){ $status .= "\t<p><strong>$error</strong></p>\n"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <div id="wrapper"> <?php echo $status; ?> <form enctype="multipart/form-data" action="<?php echo $this_file; ?>" method="post"> <ul> <li><input name="desc" type="text" onfocus="if (value=='Description') value='';" onblur="if(value=='') value='Description';" value="Description" size="55" /></li> <li><input name="large" type="file" size="55" /></li> </ul> <p><input type="submit" value="Upload Image" /></p> </form> </div> </body> </html> thanks for taking a look Jake Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/ Share on other sites More sharing options...
DarkWater Posted June 24, 2008 Share Posted June 24, 2008 Make this line: $destination = '../gallery_images/large/'; Into: $destination = '../gallery_images/large/$large'; And put it after you create $large. Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573651 Share on other sites More sharing options...
punstc Posted June 25, 2008 Author Share Posted June 25, 2008 I'm starting to go crazy i've been working on this forever . now i'm getting this error and I don't understand why can anyone help? Fatal error: Call to undefined function imagecreatefromjpeg() in /home/2008/03/jchamberlain/public_html/wpr/final_project/admin/image_add.php on line 58 <?php if(empty($_POST)) { $status = 'To add a new image, fill out the form below. When you are finished, click the Add Image button once.'; } else { $description = $_POST['desc']; $large = basename($_FILES['large']['name']); $large_tmp = $_FILES['large']['tmp_name']; $destination = '../gallery_images/large'; $error_list = array(); if(empty($description)) { $error_list[] = 'Description'; } if(empty($large)) { $error_list[] = 'Image'; } if(empty($error_list)) { mysql_connect('localhost', 'jchamberlain', 'satchel'); mysql_select_db('jchamberlain_0806'); $sql = "INSERT INTO jchamb_gallery SET description='$description' "; if(!empty($large)) { if(move_uploaded_file($large_tmp,"$destination/$large")) { $sql .= ", large='$large' "; $image_path = "$destination/$large"; // Gets temorary image name from the server $dest_path = "../gallery_images/thumb"; // Sets path to thumbnail images // Sets maximum width and height of thumbnail $max_width = 200; $max_height = 150; $size = GetImageSize($image_path); $width = $size[0]; $height = $size[1]; $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if(($width <= $max_width) && ($height <= $max_height)){ $new_width = $width; $new_height = $height; } elseif(($x_ratio * $height) < $max_height){ $new_height = ceil($x_ratio * $height); $new_width = $max_width; } else{ $new_width = ceil($y_ratio * $width); $new_height = $max_height; } $src = imagecreatefromjpeg($image_path); $dst = imagecreatetruecolor($new_width,$new_height); imagecopyresized($dst, $src, 0, 0, 0, 0, $new_width,$new_height,$width,$height); imagejpeg($dst,"$dest_path"."$large", 90); $thumb = "$dest_path"."$large"; imagedestroy($src); imagedestroy($dst); //////////////////////////// END IMAGE SCALE //////////////////////////////// $status = "<p>The image \". $image. \" has been uploaded!</p>"; $sql .= ", thumb='$thumb' "; } } if(mysql_query($sql)) { header('Location: index.php'); } else { $status ='Unable to add your images.'; } } else { $status = 'Unable to upload your images.'; $status = '<ul>'; foreach($error_list as $error_message) { $status .= "<li>$error_message</li>"; } $status .= '</ul>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Add Image</title> </head> <body> <h2>Add Image</h2> <?php echo $status; ?> <form enctype="multipart/form-data" action="<?php echo $this_file; ?>" method="post"> <ul> <li><input name="desc" type="text" onfocus="if (value=='Description') value='';" onblur="if(value=='') value='Description';" value="Description" size="55" /></li> <li><input name="large" type="file" size="55" /></li> </ul> <p><input type="submit" value="Upload Image" /></p> </form> </body> </html> I really appreciate the help, I need this to work for a school project thats due tomorrow Jake Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573704 Share on other sites More sharing options...
DarkWater Posted June 25, 2008 Share Posted June 25, 2008 You must not have GD support or you don't have JPEG support on your server. Do me a favor please. Create a new file and put this in it, then show me the output: <?php if (imagetypes() & IMG_JPEG) { echo "JPEG support enabled."; } else { echo "JPEG support not enabled."; } ?> Just like that. Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573707 Share on other sites More sharing options...
punstc Posted June 25, 2008 Author Share Posted June 25, 2008 it output this Fatal error: Call to undefined function imagetypes() in /home/2008/03/jchamberlain/public_html/wpr/final_project/admin/test.php on line 2 I'm testing all this on my schools server which we have to upload our projects to. It should have the GD library installed to because i'm basing the code off a script my lab instructor gave me thanks for helping I really appreciate this. Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573719 Share on other sites More sharing options...
DarkWater Posted June 25, 2008 Share Posted June 25, 2008 GD is not installed. Do phpinfo(); and look for GD. =X It's definitely not installed if it's giving you that message though. =X Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573733 Share on other sites More sharing options...
punstc Posted June 25, 2008 Author Share Posted June 25, 2008 I'm looking in to how to install the GD library on php.net but jsut incase I can't install it is there another way to do the resizing? Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573749 Share on other sites More sharing options...
DarkWater Posted June 25, 2008 Share Posted June 25, 2008 No. And I doubt you'll be able to install it unless you get access to the server. Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573788 Share on other sites More sharing options...
punstc Posted June 25, 2008 Author Share Posted June 25, 2008 Well thank you for taking the time to help, i really appreciate it, I guess ill just fake it with css. Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573797 Share on other sites More sharing options...
.josh Posted June 25, 2008 Share Posted June 25, 2008 well you could always ask your host to install it. frankly I'm kinda surprised they don't have it, but w/e. Failing that, you can specify dims with html tags or w/e. Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573803 Share on other sites More sharing options...
DarkWater Posted June 25, 2008 Share Posted June 25, 2008 @Crayon Violent: I think he meant literally resizing it as a thumbnail, but whatever. xD Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573805 Share on other sites More sharing options...
.josh Posted June 25, 2008 Share Posted June 25, 2008 @Crayon Violent: I think he meant literally resizing it as a thumbnail, but whatever. xD yeah that is what he meant but I was talking about alternatives to gd. I know it doesn't make a physically smaller pic but display-wise, it can be shown as thumbnail sized that way. Quote Link to comment https://forums.phpfreaks.com/topic/111746-gd-image-resizing-and-saving-thumb/#findComment-573816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.