Hi
I have found this script to resize the picture, and what I am trying to do is resize the picture before it is uploaded and stored on the server and db. Below are the two scripts, the first one uploads the files and stores them, but the second one I got from here http://uk2.php.net/imagecopyresampled to resize the image before it is uploaded. I have tried for a while now to configure the second script to work with the first with no joy. Anyone have any ideas please?
Thanks as always,
Phil
// Set the page title and include the HTML header.
$page_title = 'Upload a File';
if (isset($_POST['submit'])) { // Handle the form.
require_once ('../mysql_connect.php'); // Connect to the database.
// Function for escaping and trimming form data.
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbc);
} // End of escape_data() function.
// First name
if (!empty($_POST['first_name'])) {
$fn = escape_data($_POST['first_name']);
} else {
$fn = '';
}
// Check for a description (not required).
if (!empty($_POST['description'])) {
$d = escape_data($_POST['description']);
} else {
$d = '';
}
$picture_url = "family_pics/images/".$_FILES['upload']['name'];
// Add the record to the database.
$query = "INSERT INTO family (first_name, picture_url, description, registration_date) VALUES ('$fn', '$picture_url','$d', NOW())";
$result = @mysql_query ($query);
if ($result) {
// Create the file name.
$extension = explode ('.', $_FILES['upload']['name']);
$uid = mysql_insert_id(); // Upload ID
$filename = $_FILES['upload']['name'];
// Move the file over.
if (move_uploaded_file($_FILES['upload']['tmp_name'], "../family_pics/images/$filename")) {
echo '<p>The file has been uploaded!</p>';
} else {
echo '<p><font color="red">The file size is too big!.</font></p>';
// Remove the record from the database.
$query = "DELETE FROM family WHERE upload_id = $uid";
$result = @mysql_query ($query);
}
} else { // If the query did not run OK.
echo '<p><font color="red">Your submission could not be processed due to a system error. We apologize for any inconvenience.</font></p>';
}
@mysql_close(); // Close the database connection.
} // End of the main Submit conditional.
and the second one is:
// The file
$filename = 'test.jpg';
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);