'Foo', '200' => 'Bar', '300' => 'Toast', '400' => 'Other' ); $offset = 5; $max_image_width = '550'; $max_image_height = '600'; $max_upload_bytes = '100000'; require_once('dbconn.php'); $self = basename($_SERVER['PHP_SELF']); ?> <?php echo $self; ?>

Images for Shopping Cart (inventory1)

Results ...'; echo "\n".''; echo "\n".'
'; if($submit == 'Upload Image'){ if($id == 'new_item'){ if($item_name == ''){ $errors[] = 'No Item name was entered'; } } if(file_exists($file_tmp) && list($image_width, $image_height, $image_type1, $img_attrib) = getimagesize($file_tmp) ){ if($image_width > $max_image_width){ $errors[] = 'The image width exceeds the allowed width of '.$max_image_width. ' pixels by '.($image_width-$max_image_width).' pixels'; } if($image_height > $max_image_height){ $errors[] = 'The image height exceeds the allowed height of '.$max_image_height. ' pixels by '.($image_height-$max_image_height).' pixels'; } if(!$data = addslashes(fread(fopen($file_tmp, "r"), filesize($file_tmp)))){ $errors[] = 'Unable to read file'; } if(filesize($file_tmp) > $max_upload_bytes){ $errors[] = 'Image exceeds maximum file size of '.number_format($max_upload_bytes); } }else{ $errors[] = 'Unable to locate '.$file_tmp; } if(count($errors) > 0){ echo "\n".'
    '; for ($i = 0; $i < count($errors); $i++){ echo "\n".'
  1. '.$errors[$i].'
  2. '; } echo "\n".'
'; echo "\n".'
'; echo "\n".'

Image Upload

'; echo "\n".''; remove_temp_file($file_tmp); exit; }else{ if($id == 'new_item'){ $qry = sprintf("INSERT INTO inventory1 (id, hidden, item_name, image, image_width, image_height, image_type1, image_type2, img_attrib) VALUES ('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s', '%s')", '', '1', addslashes($item_name), $data, $image_width, $image_height, $image_type1, $filetype, addslashes($img_attrib)); $res = mysql_query($qry); $insert_id = mysql_insert_ID(); if(mysql_affected_rows() == 0){ echo "\n".'

Query failed.
Query: '.$qry.'

'.mysql_error().'

'; }elseif(mysql_affected_rows() == 1){ echo "\n".'

'.$insert_id.' image uploaded

'; echo "\n".'

'; } }else{ $qry = sprintf("UPDATE inventory1 SET image = '%s', image_width = '%s', image_height = '%s', image_type1 = '%s', image_type2 = '%s', img_attrib = '%s' WHERE id = '$id'", $data, $image_width, $image_height, $image_type1, $filetype, addslashes($img_attrib)); mysql_query($qry); $success = sprintf("Updated %d record\n", mysql_affected_rows()); if(!mysql_query("COMMIT")) { echo "\n".'

Query failed.
Query: '.$qry.'

'.mysql_error().'

'; echo mysql_error() > 0 ? "\n".'

'.mysql_error().'

' : ''; }else{ echo "\n".'

'.$success.'

'; echo "\n".'

'; echo "\n".'

If no image appears,
then the upload failed.

'; } } remove_temp_file($file_tmp); } }elseif($delete == 'Delete Image'){ if($id == 'new_item'){ $errors[] = 'Invalid selection'; } if(count($errors) > 0){ echo "\n".'
    '; for ($i = 0; $i < count($errors); $i++){ echo "\n".'
  1. '.$errors[$i].'
  2. '; } echo "\n".'
'; echo "\n".''; echo "\n".'

Image Upload

'; echo "\n".''; exit; } $qry = sprintf("UPDATE inventory1 SET image = '%s', image_width = '%s', image_height = '%s', image_type1 = '%s', image_type2 = '%s', img_attrib = '%s' WHERE id = '$id'", '', '', '', '', '', ''); mysql_query($qry); $success = sprintf("Deleted records: %d\n", mysql_affected_rows()); if(!mysql_query("COMMIT")) { echo "\n".'

No image deleted. This record ID probably did not have an image.

'; }else{ echo "\n".'

'.$success.'

'; echo "\n".'

Image deleted.

'; } }else{ echo "\n".'

Unknown submission.

'; } echo "\n".''; echo "\n".'

Image Upload

'; echo "\n".''; exit; Case 'GET': default: ?>
0 ? mysql_result($res,0,0) : 0; $qry = "SELECT id, item_name, image_width, image_height FROM inventory1 ORDER BY item_name LIMIT $row_start, $limit"; }else{ $res = mysql_query('SELECT COUNT(*) FROM inventory1 WHERE catid = "'.$catid.'"'); $record_count = $res > 0 ? mysql_result($res,0,0) : 0; $qry = "SELECT id, catid, item_name, image_width, image_height FROM inventory1 WHERE catid = '$catid' ORDER BY item_name"; } $res = mysql_query($qry); $num_rows = mysql_num_rows($res); if($res){ if($num_rows == 0) { echo "\n".'

No records found

'; }else{ $i = 0; echo "\n".''; echo "\n".''; echo "\n".''; while($ary = mysql_fetch_assoc($res)) { while(list($key,$val) = each($ary)) { $$key = htmlspecialchars(stripslashes(trim($val))); } if(strlen($item_name) > 255) { $item_name = substr($item_name,0,25).'...'; } if($image_width > 0) { $display_image = ''.$item_name.''; }else{ $display_image = ' '; } echo "\n".''; } echo "\n".''; echo "\n".'
Select a radio button, then Upload or Delete the associated image.
Maximum image size: '.$max_image_width.'x'.$max_image_height.' pixels
If the Width/Height columns are 0, no image is associated.
IDItem NameWH 
'.$item_name.''.$image_width.''.$image_height.''.$display_image.'
Upload image for a new, hidden page
'; if($record_count > $limit){ echo "\n".'
Pages '; $page_count = intval($record_count / $limit); if($record_count % $limit){ $page_count++; } for($i = 1; $i<=$page_count; $i++){ $rs = $limit * ($i - 1); echo $rs == $row_start ? $i : ''.$i.''; echo $i < $page_count ? ' - ' : ' '; } echo "\n".'

'; } } }else{ echo "\n".'

'.mysql_error().'
'.$qry.'

'; } ?>
$val){ echo in_array($key, $parts) ? "\n".''.$val.'
' : ''; } ?>
All categories
Item name (required for new uploads, max. 255 chars.)

Click the Browse button to locate the image file

Image Upload  ' : ''; ?>