mrblues Posted February 6, 2007 Share Posted February 6, 2007 Hi.. I need urgent help so bad, i have this upload form that works like a charm, but i would like it to resize images on upload like 600 x 400 but it shall keep it`s normal shape if you understand it shoul not distort the image ----how do i do that and where should i put the new kode in the script. you have to know i`m a newbie to php so you have to be gentle I hope someone can explain it to me or show me please i`m going crazy over this. Here`s the upload script... <?php //This is the directory where images will be saved $target = "billeder/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("*********", "********", "******") or die(mysql_error()); mysql_select_db("*********") or die(mysql_error()); //Writes the information to the database mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')"); //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> <form enctype="multipart/form-data" action="add.php" method="POST"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br> Photo: <input type="file" name="photo"><br> <input type="submit" value="Add"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/37377-upload-form-with-resize-on-upload-hellllp-please/ Share on other sites More sharing options...
ultrus Posted February 7, 2007 Share Posted February 7, 2007 Hello mrblues, My brain can't handle the php right now as I am somewhat new-ish myself, tired, and lazy tonight. I can however handle the math right now. To make your image scale proportionally, use some script like this: <?php //get the image width and height //some code goes here that gets the image width and height, we'll just fake it for now below $imgWidth = 700; $imgHeight = 350; //what is the width you want the image to scale to? You could do this with //height too, but just pick one or the other $newImgWidth = 400; //we picked a new width, so we need to figure out the new height $newImgHeight = round($newImgWidth * $imgHeight / $imgWidth); //see the result echo $newImgHeight; ?> I hope this helps inspire. Link to comment https://forums.phpfreaks.com/topic/37377-upload-form-with-resize-on-upload-hellllp-please/#findComment-178826 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.