picture/file upload

No replies
Last seen: 9 years 21 weeks ago
Joined: 2012-12-06


i have a drupal 6.x module which was programed for our company which shall upload a product picture (admin website settings) and display it in a product table (frontend). the picture will be stored in the database but it will not be displayed.

at the moment i'm going through chris' assets module, but i'm very new to this subject and i need a quick help to get my module running.

here is the code:

//The form
function kajinga_settings_formA() {

$form = array(); //intialize form array

//Image upload field
$form['kajinga_productimage'] = array(
'#type' => 'file',
'#title' => t('Wählen sie ein Produktbild'),
'#size' => 55,
'#maxlength' => 100,
'#description' => t('Laden sie ein Produktbild hoch, um es mit dem Affiliate-Link anzuzeigen.'),
'#weight' => 1,

//Submit button: kajinga_addpproduct
$form['kajinga_addproduct'] = array(
'#type' => 'submit',
'#value' => t('Affiliate-Link erstellen'),
'#weight' => 2,

$form['#attributes']['enctype'] = 'multipart/form-data';
$form['#validate'][] = 'product_validate_picture';

return $form;

//Picture Validation and upload
function product_validate_picture(&$form, &$form_state) {

$validators = array(
'file_validate_is_image' => array(),
'file_validate_size' => array(100 * 1024),
if ($file = file_save_upload('kajinga_productimage', $validators))
// Remove the old picture.
if (isset($form_state['values']['kajinga_productimage']->image_path) && file_exists($form_state['values']['kajinga_productimage']->image_path))
$productid = 0;
if (!isset($form_state['values']['productid']))
{ // Execute in case of new product
$query = "SHOW TABLE STATUS LIKE 'users_products'";
$rs = db_query($query);
$row = db_fetch_object($rs);
$productid = isset($row->Auto_increment) ? $row->Auto_increment : 0;
$productid = $form_state['values']['productid'];

$info = image_get_info($file->filepath);
$destination = variable_get('product_picture_path', 'images') .'/picture-'. $productid .'.'. $info['extension'];
if (file_copy($file, $destination, FILE_EXISTS_REPLACE))
$form_state['values']['picture'] = $file->filepath;
form_set_error('kajinga_productimage', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.",
array('%directory' => variable_get('product_picture_path', 'images'))));


the result xou can see here:

what can i do to get the picture displayed? is there a better way to code this?

thx, martin

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:

Contact us

Below are the supported keyboard shortcuts for our video player.

Start / stop video
Go to next video
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
Jump to a percentage (2 is 20%, for example)
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
1 month
6 months
10% off
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.