hey guys, been searching and trying but cant what time looking for
im using the following
<?php
session_start();
// CONFIG
$serverpath = "/home/****/public_html/img1/"; // Path to where images should be uplothe server.
$thumbpath = "/home/****/public_html/img1/thumbs/";
$urltoimages = "http://****/img1/"; // Web address to where the images are accessible from.
$maxsize = "2000000"; // Example - 20000 is the same as 20kb
$aircraft = $_POST["aircraft"];
$genre = $_POST['genre'];
$airline = $_POST['airline'];
$reg = $_POST['reg'];
$serials = $_POST['serials'];
$location = $_POST['location'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$comments = $_POST['comments'];
$copyright = $_POST['copyright'];
$name_photos = $_POST['name_photos'];
// CONFIG END
function makeRandomPassword() {
$salt = "0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$randcode = $random_password;
$file = $_FILES['file']['name'];
$name = time() ."$randcode". substr($file, -4);
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big - please reduce file size and try again.";
}
else {
$path = "$serverpath/" . $name;
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists - please rename the file and reupload.";
exit;
}
}
// resize the image to 850 x 561
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
// Import the image to use
//----------------------------------------------------------------------
// Here we create the thumbnail
$pathmain = '/home/*****/public_html/img1/thumbs/';
$dst = ImageCreatetruecolor(200, 150);
ImageCopyResampled($dst, $name, 0,0,0,0, 200, 150, 300, 225);
error_reporting(0);
header("Content-type: image/jpeg");
ImageJPEG($dst, $pathmain.$name, 60);
ImageDestroy($src);
ImageDestroy($dst);
include 'config.php';
mysql_connect("$db_host","$db_user","$db_pass") or die (mysql_error());
mysql_select_db ("$db_name") or die (mysql_error());
$username = $_SESSION['name'];
$result = "INSERT INTO photos (id,genre,aircraft, airline, reg, serials, comments, copyright, ip_address, file_name,status,awhen,accepted,date_taken,location)
VALUES('NULL', '$genre', '$aircraft', '$airline', '$reg', '$serials', '$comments', '$username', '$address_ip', '$name', 'pending' ,now(), '0', '$day|$month|$year', '$location')";
mysql_query($result);
include 'image_uploaded.php';
}
}
?>
to do upload image, save it with a random file name, store it to a db and then to create a thumbnail.
im looking to automatically resize the uploaded image to x by y then save the image at that size.
any idea how i would do that using the script above?