In the following code once I introduced if (isset($_POST['photo_filename'])) { } on the photo_filename (file field) if I add a picture that part of the script still isnt exicuted .. Been a file field is a differend function needed?
code:
Code: Select all
$item = $_REQUEST['item'];
$desc = $_REQUEST['desc'];
$code = $_REQUEST['dode'];
$price = $_REQUEST['price'];
$stock = $_REQUEST['stock'];
$link = $_REQUEST['link'];
$sql = "INSERT INTO items (item, desc, price, code, picture, link, stock) VALUES ('$item', '$desc', '$price', '$code', '0', '$link', '$stock')";
$result = mysql_query($sql);
if (isset($_POST['photo_filename'])) {
$images_dir = 'images/products';
$known_photo_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif');
$gd_function_suffix = array(
'image/pjpeg' => 'JPEG',
'image/jpeg' => 'JPEG',
'image/gif' => 'gif');
$photos_uploaded = $_FILES['photo_filename'];
$photoFileName = $_FILES['photo_filename'];
if (!array_key_exists($photos_uploaded['type'], $known_photo_types)) {
require 'preupload.php';
echo '<center><font color="red"><b>File is not a photo!</b></font></center><br>';
return;
}
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'];
$extention = $known_photo_types[$filetype];
$filename = $new_id.".".$extention;
$sql = "UPDATE items SET picture='$filename' WHERE itemId='$new_id'";
$result = mysql_query($sql);
copy($photos_uploaded['tmp_name'], $images_dir."/".$filename);
$size = GetImageSize( $images_dir."/".$filename );
$Config_tbwidth_wide = 80; // width of wide image
$Config_tbheight_wide = 80; // height of wide image
$Config_tbwidth_tall = 80; // width of tall image
$Config_tbheight_tall = 80; // height of tall image
if ($size[0] > $size[1]) {
$thumbnail_width = $Config_tbwidth_wide;
$thumbnail_height = (int)($Config_tbwidth_wide * $size[1] / $size[0]);
if ($thumbnail_height > $Config_tbheight_wide) {
$thumbnail_height = $Config_tbheight_wide;
$thumbnail_width = (int)($Config_tbheight_wide * $size[0] / $size[1]);
}
}else{
$thumbnail_width = (int)($Config_tbheight_tall * $size[0] / $size[1]);
$thumbnail_height = $Config_tbheight_tall;
if ($thumbnail_width > $Config_tbwidth_tall) {
$thumbnail_width = $Config_tbwidth_tall;
$thumbnail_height = (int)($Config_tbwidth_tall * $size[1] / $size[0]);
}
}
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = "ImageCreateFrom".$function_suffix;
$function_to_write = "Image".$function_suffix;
$source_handle = $function_to_read ( $images_dir."/".$filename );
if ($source_handle) {
$destination_handle = ImageCreateTrueColor ( $thumbnail_width, $thumbnail_height );
ImageCopyResampled( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] );
}
$function_to_write( $destination_handle, $images_dir."/tb_".$filename, 100 );
ImageDestroy($destination_handle );
if ($size[0] > '100') {
$Config_width_wide = 500; // width of wide image
$Config_height_wide = 475; // height of wide image
$Config_width_tall = 475; // width of tall image
$Config_height_tall = 500; // height of tall image
if($size[0] > $size[1]) {
$image_width = $Config_width_wide;
$image_height = (int)($Config_width_wide * $size[1] / $size[0]);
if ($image_height > $Config_height_wide) {
$image_height = $Config_height_wide;
$image_width = (int)($Config_height_wide * $size[0] / $size[1]);
}
}else{
$image_width = (int)($Config_height_tall * $size[0] / $size[1]);
$image_height = $Config_height_tall;
if ($image_width > $Config_width_tall) {
$image_width = $Config_width_tall;
$image_height = (int)($Config_width_tall * $size[1] / $size[0]);
}
}
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = "ImageCreateFrom".$function_suffix;
$function_to_write = "Image".$function_suffix;
$source_handle = $function_to_read ( $images_dir."/".$filename );
if ($source_handle) {
$destination_handle = ImageCreateTrueColor ( $image_width, $image_height );
ImageCopyResampled( $destination_handle, $source_handle, 0, 0, 0, 0, $image_width, $image_height, $size[0], $size[1] );
}
$function_to_write( $destination_handle, $images_dir."/".$filename, 90 );
ImageDestroy($destination_handle );
}
}