QuizToon Posted August 24, 2009 Share Posted August 24, 2009 Hi all, Looking for some help on a problem I have been working on for some time now Basically the form and process below work perfectly well. User uploads an image, the image is saved to a pictures folder and the path is saved in the database. No problems with that. The problem is the size of the images being uploaded. I want the image that is selected for upload to be resized by the script so that it is no larger than 800x600. I have tried to get to grips with the GD Library but alas I must be too thick to follow it and just cannot get it to work. Obviously if the image already 800x600 or smaller then it can be left as it is. Please could somebody put this thicko out of his mysery. <?php $uploadDir = 'pictures/'; $fileUploaded = 0; // set a flag for use later // connection parameters should be in a seperate file! //$dbhost = 'localhost'; //$dbuser = 'username'; //$dbpass = 'password'; //$dbname = 'dbname'; include('/home/sites/mysite.com/db_config/config.php'); $database = mysql_connect($hostname,$username,$password) or die("Could not connect to server"); mysql_select_db($table,$database) or die("Could not find table"); //$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); //mysql_select_db($dbname); //////////////////////////////////// if(isset($_POST['upload'])) { $id = $row['id']; $title = addslashes($_POST['title']); $detail = addslashes($_POST['detail']); $picinfo = addslashes($_POST['picinfo']); //$year = addslashes($_POST['year']); // check if a file has been uploaded if($_FILES['userfile']['error'] != 4) { // error code 4 meaning that no image is present $fileUploaded = 1; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // the files will be saved in filePath $filePath = $uploadDir . $fileName; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } } else { // if no file added, generate empty variables so as not to break the query $fileName = ''; $fileSize = ''; $fileType = ''; $filePath = ''; } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $query = "INSERT INTO tablename(name, size, type, path, title, detail, picinfo) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$title', '$detail', '$picinfo')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); mysql_close($database); // if a file was uploaded, the fileUploaded variable will be set to 1 if($fileUploaded == 1) { echo "<br>File uploaded<br>"; // show the image after upload - comment this out if not required - good for checking though echo '<img src="'. $uploadDir .'/'.$_FILES['userfile']['name'][$i] .'" >'; $movedtolocation="pictures/".$_FILES['upload']['name'];# basically, take the location of wher the image is stored.. } } ?> <link href="styleadmin.css" rel="stylesheet" type="text/css"> <form action="" method="post" enctype="multipart/form-data" name="uploadform"> <table width="609" align="center" cellpadding="1" cellspacing="1"> <tr> <td colspan="4" align="center"> </td> </tr> <tr> <td width="165"><p class="subtitle">Main Title :</p></td> <td width="437" colspan="3"><p> <input name="title" type="text" size="35"> </td> </tr> <tr> <td width="165" valign="top"> </td> <td colspan="3"> </td> </tr> <tr> <td width="165" valign="top"><p class="subtitle"> Blog :</p> <p align="center" class="small"> </p></td> <td colspan="3"><textarea name="detail" id="detail" cols="50" rows="20"></textarea></td> </tr> <tr> <td width="165"><p class="subtitle">Select Picture:</p></td> <td colspan="3"><p align="center"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <input name="userfile" type="file" class="box" id="userfile" size="35"> <span class="small"> <br> Leave blank if no picture to upload</span><br> <br> </p></td> <tr> <td width="165">Picture Info</td> <td colspan="3"><p align="left"><input name="picinfo" type="text" size="35"></p></td> </tr> <tr><td colspan="4" align="center"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/171639-image-upload-sizing/ Share on other sites More sharing options...
Adam Posted August 24, 2009 Share Posted August 24, 2009 Have you taken a look at imagecopyresampled? Link to comment https://forums.phpfreaks.com/topic/171639-image-upload-sizing/#findComment-905059 Share on other sites More sharing options...
QuizToon Posted August 24, 2009 Author Share Posted August 24, 2009 I have looked through all of these but am not sure how to incorporate that script into my script Link to comment https://forums.phpfreaks.com/topic/171639-image-upload-sizing/#findComment-905067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.