Thank you so much for taking the time to do that for me, and thank your daughter.
With the complete page here (your code instead of the previous):
Code: Select all
<?php
$uploadedfile = $_FILES['userfile']['tmp_name'];
//$uploadedfile_dimensions = getimagesize($uploadedfile);
require "./admin_header.php";
$category = mysql_real_escape_string($_REQUEST['category']);
$title = mysql_real_escape_string($_REQUEST['title']);
$author = mysql_real_escape_string($_REQUEST['author']);
$designer_id = mysql_real_escape_string($_REQUEST['designer_id']);
$designer_name = mysql_real_escape_string($_REQUEST['designer_name']);
$description = mysql_real_escape_string($_REQUEST['description']);
$publisher = mysql_real_escape_string($_REQUEST['publisher']);
$pages_desctiption = mysql_real_escape_string($_REQUEST['pages_description']);
$binding = mysql_real_escape_string($_REQUEST['binding']);
$illustrations = mysql_real_escape_string($_REQUEST['illustrations']);
$age_range = mysql_real_escape_string($_REQUEST['age_range']);
$composition = mysql_real_escape_string($_REQUEST['composition']);
$materials = mysql_real_escape_string($_REQUEST['materials']);
$size = mysql_real_escape_string($_REQUEST['size']);
$brand = mysql_real_escape_string($_REQUEST['brand']);
$country_of_origin = mysql_real_escape_string($_REQUEST['country_of_origin']);
if(isset($_REQUEST['product_id']) && (int)$_REQUEST['product_id'] > 0)
$product_id = (int)$_REQUEST['product_id'];
else
list($product_id) = mysql_fetch_row(mysql_query('SELECT MAX(product_id) + 1 FROM products'));
mysql_query('
INSERT INTO products (
product_id,
title,
description,
author,
publisher,
pages,
binding,
illustrations,
designer_id,
designer_name,
composition,
materials,
size,
brand,
country_of_origin,
suggested_age_range
)
VALUES (
'.$product_id.',
"'.$title.'",
"'.$description.'",
"'.$author.'",
"'.$publisher.'",
"'.$pages_desctiption.'",
"'.$binding.'",
"'.$illustrations.'",
"'.$designer_id.'",
"'.$designer_name.'",
"'.$composition.'",
"'.$materials.'",
"'.$size.'",
"'.$brand.'",
"'.$country_of_origin.'",
"'.$age_range.'"
)
');
$product_version = mysql_insert_id();
if(!isset($_REQUEST['product_id']) || (int)$_REQUEST['product_id'] < 1)
{
mysql_query('
INSERT INTO product_status (
product_id,
category,
show_on_website,
new
)
VALUES (
'.$product_id.',
"'.$category.'",
1,
1
)
');
echo mysql_error();
}
for($i = 0; $i < count($_REQUEST['price']); $i++)
{
$variant = mysql_real_escape_string($_REQUEST['variant'][$i]);
$price = mysql_real_escape_string($_REQUEST['price'][$i]);
$show_item = ($_REQUEST['show_item'][$i] == 'on')? 'true':'false';
if($price != '')
{
mysql_query('
INSERT INTO prices (product_id, version, variant_description, price_inc_vat)
VALUES (
'.$product_id.',
'.$product_version.',
"'.$variant.'",
"'.$price.'"
)
');
}
}
// If the file has been uploaded run this
if(is_uploaded_file($_FILES['image']['tmp_name']))
{
// Put the uploaded image tempory filename into a variable
$input_image = $_FILES['image']['tmp_name']
// Get the file dimensions of the uploaded file into an array - we are interested in the width $size[0] and height $size[1]
$size = getimagesize( $input_image );
// Setup some variables - I think it makes the code easier to read if long paths are outside the functions in a variable
$thumb_width = '180';
$thumb_save = $_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_small.jpg';
$large_width = '250';
$large_save = $_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_small.jpg'
// Create thumbnail
$thumb_height = ( int )(( $thumb_width/$size[0] )*$size[1] );
$thumbnail = ImageCreateTrueColor( $thumb_width, $thumb_height );
$src_img = ImageCreateFromJPEG( $input_image );
ImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1] );
ImageJPEG( $thumbnail, $thumb_save );
ImageDestroy( $thumbnail );
// Create large
$large_height = ( int )(( $large_width/$size[0] )*$size[1] );
$large = ImageCreateTrueColor( $large_width, $large_height );
$src_img = ImageCreateFromJPEG( $input_image );
ImageCopyResampled( $large, $src_img, 0, 0, 0, 0, $large_width, $large_height, $size[0], $size[1] );
ImageJPEG( $large, $large_save );
ImageDestroy( $large );
}
// Do not know what this bit below is about - would have been helpful if the original developer had added comments
else if(isset($_REQUEST['product_id']) && (int)$_REQUEST['product_id'] > 0)
{
$old_product_version = $product_version - 1;
copy($_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$old_product_version.'_large.jpg', $_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_large.jpg');
copy($_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$old_product_version.'_small.jpg', $_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_small.jpg');
}
echo 'SUCCESS';
// To be correct you should check the file is actualy saved with something like file_exists( ) although that sometimes will not work
// so could use something like if(fopen($thumb_save, 'r')) echo "Thumbnail sucess"; else echo "Thumbnail fail"; if(fopen($thumb_save, 'r')) echo "Large sucess"; else echo "Large fail"; - UNTESTED
// You can add echos through the code to confirm variable contents especialy good to check file save paths etc.
// e.g. echo $thumb_save; after this line $thumb_save = $_SERVER['DOCUMENT_ROOT'].'/product_images/'.$product_id.'-'.$product_version.'_small.jpg';
?>
I get syntax errors on these 2 lines flag up in Dreamweaver:
Code: Select all
$size = getimagesize( $input_image );
and
Code: Select all
$thumb_height = ( int )(( $thumb_width/$size[0] )*$size[1] );
Am thinking I may need to amend the code at the top as this is possibly referencing the Imagick?
I tried to add a new product with this full page and got this in the logs
Code: Select all
PHP Parse error: syntax error, unexpected T_VARIABLE in /home/wozwebs/public_html/admin/save_product.php on line 120
where line 120 is
Code: Select all
$size = getimagesize( $input_image );
I don't think it's far away. Will keep meddling. Thanks again