I want my code to 1) detect if the image is larger than 50x50px and if it's larger than 50x50 pixels, I want the code to scale the image down to 50x50 or less (50x49, etc, etc as long as it doesn't look stretched out or anything.. I don't really know what that's called). Anyways, I have the upload code here:
require ('rand.php'); //this file generates random number
require ('db.php'); //connect to DB
equire ('config.inc.php');
// Assigning the option variables
$dir = $icon_upload_dir; //located in config.inc.php
$max = 5000;
$allowed = array("gif"); //allowed filetype
//turns $_FILES['file_field']['name'] to randomnumber.gif
$files_name = (str_rand(7, '123456789').".gif"); //turn
// Check to verify that the file to be uploaded was specified!
if(!isset($files_name) || $files_name == "none") {
echo "No file to be uploaded";
echo "Please try again";
die;
}
// Check to verify if the file extension is in the allowable list or not!
$ext_array = explode( "." , $_FILES['file_field']['name'] );
$ex = $ext_array[count($ext_array) - 1];
$ex = strtolower($ex);
if(!in_array($ex,$allowed)) {
echo "Incorrect file type!";
die;
}
// Converting the size of the file being uploaded to KB from bytes.
$_FILES['file_field']['size'] = $_FILES['file_field']['size']/1000;
// Check to verify that the filesize is less than the allowable filesize
if($size > $max) {
echo "The filesize of the file you have uploaded exceeds the maximum allowable file size which is $max KB.";
}
// Moving the uploaded file to the specified directory
if(move_uploaded_file($_FILES['file_field']['tmp_name'], $dir."/".$files_name)) {
//puts url into user field
header("Location: myprofile.php"); //forward to profile after upload
mysql_query("UPDATE users SET u_icon = '".$files_name."', icon_approved = '0' WHERE username = '".$_COOKIE['Username']."'"); //put the name of image into database table (randomnumber.gif)
die;
}
else {
echo "The file upload has failed!";
die;
}
I'm missing the whole resize code but I don't know what to search for and how to combine it with my upload code.
Thanks in advance for any help.