Ok i know i have seen hundreds of posts on resizing images but they all seem to be about manipulating an image on your server and displaying it at a different size
I want to use the upload image idea that is sticky at the top of the php forum and incorporate the following
When a user uploads the image it will first be checked for width and height and which ever is the shorter will be resized to 200px and the other dimention will be resized proportionally
so that no matter if the image is in portrait or landscape it will always be resized to the same size just the width and height will be opposite way round depending on which orientation the image is if you get what i mean
Then once the image has been set to its new size i want it saved to the uploaded folder on my site
I firstly need this for making sure all images fit a certain size while retaining their aspect ratio but secondly if someone uploads a huge 3000px by 4000px image i dont want to just display it at smaller dimentions and leave such a huge file on my server taking up unneeded disk space
Can anyone help with modifying the script, any suggestions
Below is the exact code im currently using havent finished it all fully yet as it also ads some info to a database regarding the user details and some info about the image location but i just need the image to be resized before saving it to the upload folder on the server
[CODE]<?php
$uploadsDirectory = $_SERVER[‘DOCUMENT_ROOT’].’/WWPL/members/property-photos/’;
$uploadSuccess = ‘http://’ . $_SERVER[‘HTTP_HOST’].’/members/submit-listing.php?sent=1′;
$uploadForm = ‘http://’ . $_SERVER[‘HTTP_HOST’].’/members/submit-listing.php’;
$fieldname = ‘photo’;
$errors = array(1 => ‘php.ini max file size exceeded’,
2 => ‘html form max file size exceeded’,
3 => ‘file upload was only partial’,
4 => ‘no file was attached’);
isset($_POST[‘submit’])
or error(‘the upload form is neaded’, $uploadForm);
($_FILES[$fieldname][‘error’] == 0)
or error($errors[$_FILES[$fieldname][‘error’]], $uploadForm);
@is_uploaded_file($_FILES[$fieldname][‘tmp_name’])
or error(‘not an HTTP upload’, $uploadForm);
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.’-‘.$_FILES[$fieldname][‘name’]))
{
$now++;
}
@move_uploaded_file($_FILES[$fieldname][‘tmp_name’], $uploadFilename)
or error(‘receiving directory insuffiecient permission’, $uploadForm);
$propertyname = $_POST[‘propertyname’];
$address = $_POST[‘address’];
$city = $_POST[‘city’];
$state = $_POST[‘state’];
$zip = $_POST[‘zip’];
$country = $_POST[‘country’];
$email = $_POST[’email’];
$phone = $_POST[‘phone’];
$website = $_POST[‘website’];
$description = $_POST[‘description’];
$photo = $uploadFilename;
$userid = $check[“id”];
$date = date();
$icon = $_POST[‘icon’];
$qry = “INSERT into listings
(userid, propertyname, address, city, state, zip, country, lat, lng, icon, phone, email, website, description, photo, date)
VALUES
(“$userid”, “$propertyname”, “$address”, “$city”, “$state”, “$zip”, “$country”, “$lat”, “$lng”, “$icon”, “$phone”, “$email”, “$website”, “$description”, “$photo”, “$date”)”;
$result = mysql_query($qry);
header(‘Location: ‘ . $uploadSuccess);
function error($error, $location, $seconds = 5)
{
header(“Refresh: $seconds; URL=”$location””);
echo ‘<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”‘.”n”.
‘”http://www.w3.org/TR/html4/strict.dtd”>’.”nn”.
‘<html lang=”en”>’.”n”.
‘ <head>’.”n”.
‘ <meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″>’.”nn”.
‘ <link rel=”stylesheet” type=”text/css” href=”stylesheet.css”>’.”nn”.
‘ <title>Upload error</title>’.”nn”.
‘ </head>’.”nn”.
‘ <body>’.”nn”.
‘ <div id=”Upload”>’.”nn”.
‘ <h1>Upload failure</h1>’.”nn”.
‘ <p>An error has occured: ‘.”nn”.
‘ <span class=”red”>’ . $error . ‘…</span>’.”nn”.
‘ The upload form is reloading</p>’.”nn”.
‘ </div>’.”nn”.
‘</html>’;
exit;
}