ok im not sure what is going on but this isn't working for me. My one lab instructor gave me this script to play around with so I could learn how to create thumb nails dynamically but after I made some changes things aren't working. When I try to upload the image it tells me I haven't provided an image everytime can someone please take a look and see what they think. heres the code
Thanks, a lotCode:<?php $target_path = "../gallery_images/large"; // Where the file is going to be placed. Permissions on this folder must be set to 777 $this_file = basename($_SERVER['PHP_SELF']); // Sets $this_file to the name of this php file include('../php/db_connect.php'); // Includes file to connect to database // Uploads image to the server and adds entry to database if($_POST){ $error_list = array(); // Get base image name and description $large = basename($_FILES['large']['large_tmp']); $desc = $_POST['desc']; if(empty($large)){ $error_list[] = 'Image'; } if(empty($desc) OR ($desc == 'Description')){ $error_list[] = 'Description'; } else{ // Replace spaces with '_' and make imagename lowercase $large = ereg_replace(' ','_',"$large"); $large = strtolower($large); $target_path = $target_path . $large; // Add the original imagename to our target path. $sql = "SELECT large FROM jchamb_gallery "; $sql .= "WHERE large='$large' "; if (mysql_query($sql)) { $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $image_check = $row['large']; } else{ $_FILES['large']['large_tmp']; // Gets temorary image name from the server // Moves the temporary image to its new location if(move_uploaded_file($_FILES['large']['large_tmp'], $target_path)){ //////////////////////////// IMAGE SCALE //////////////////////////////// $image_path = "../gallery_images/large/$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); $thumb = imagejpeg($dst,"$dest_path"."$large", 90); imagedestroy($src); imagedestroy($dst); //////////////////////////// END IMAGE SCALE //////////////////////////////// $status = "<p>The image ". $image. " has been uploaded!</p>"; // Inserts image name into table 'images' $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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Upload Image</title> </head> <body> <div id="wrapper"> <?php echo $status; ?> <form enctype="multipart/form-data" action="<?php echo $this_file; ?>" method="post"> <ul id="input"> <li><input type="text" name="desc" value="Description" onfocus="if (value=='Description') value='';" onblur="if(value=='') value='Description';" /></li> <li><input type="file" name="large" id="large" /></li> </ul> <p><input type="submit" value="Upload Image" /></p> </form> </div> </body> </html>
Jake



Reply With Quote


Bookmarks