Richzilla Posted July 19, 2007 Share Posted July 19, 2007 Hi All, Back again. This time I'm really stuck. So, I'm currently uploading an image from a forms page along with the information to my server and also adding the filename etc to my sql database. I'm checking that the files are only jpg and gif files and that they are less than 3MB in size. I'd like to now resize this image and upload alsoto the same location as the large image but with the extension _small. e.g - largeimage_small.gif So essentially I'd like to add the large image to the server and also the small resized image (max 150 pixel width). I can find a way of resizing the image by opening it as is below. So far the script for upload the image is working really well. Now I need to have the smaller image version added also. Any help would be greatly apprecaited. You're all such wizards and I'm still a mear novice. Here's the code - [code <? $event = $_POST['event']; $date = @$_POST['date']; $flyer = @$_POST['uploaded']; $user="xxxx"; $pass="xxxx"; $host = "xxxx"; $dbase="xxxx"; $table = "events"; mysql_connect($host,$user,$pass); mysql_select_db($dbase) or die("Unable to select database"); $query = "SELECT * FROM events WHERE event ='$event'"; if ($result = mysql_query($query) or die(mysql_error()) > 0) { if (mysql_num_rows($result)) { echo "Error : This event is already in the database"; } else { $filename = basename($_FILES['uploaded']['name']); if((!empty($_FILES["uploaded"])) && ($_FILES['uploaded']['error'] == 0)) { $tag = "events"; $ext = substr($filename, strrpos($filename, '.') + 1); $goback = "<a href=\"http://www.mysite.co.uk/add_event.php\">back</a>"; if (($ext == "jpg") || ($ext == "gif") && ($_FILES["uploaded"]["size"] < 3000000)) { $newname = dirname(events).'/upload/'.$filename; if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded']['tmp_name'],$newname))) { echo "You have successfully entered the following information into the database - <br> <br> Event : $event <br>Date : $date <br>Flyer : "; $query = "INSERT INTO events VALUES ('','$event','$date','','$tag$newname')"; $result = mysql_query($query) or die(mysql_error()); // How do I now open the image to resize it??? $image = open_image('$tag$newname'); $width = imagesx($image); $height = imagesy($image); $new_width = 150; $new_height = $height * ($new_width/$width); $image_resized = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); //How do I now move the file to my server and also add the filename to my database?? mysql_close(); } else { echo "Error: A problem occurred during file upload! Please go $goback and try again"; } } else { echo "Error: File ".$_FILES["uploaded"]["name"]." already exists. Please rename and go $goback and try again"; } } else { echo "Error: Only jpg and gif files under 3MB are accepted for upload. <br> Go $goback and try again"; } } else { $query = "INSERT INTO events VALUES ('','$event','$date','','')"; $result = mysql_query($query) or die(mysql_error()); echo "You have successfully entered the following information into the database - <br> <br> Event : $event <br>Date : $date <br>"; mysql_close(); } }} ?> code] Quote Link to comment Share on other sites More sharing options...
Richzilla Posted July 20, 2007 Author Share Posted July 20, 2007 Bump. All i need to do is work out a way of resizing images that are on my server and then reuploading them. Anyone know how to do this? Quote Link to comment 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.