1. Create URL link to form
$items [' qianfeng/add '] = Array (
' title ' + t (' join information '),
' Page callback ' = ' drupal_get_form ',
' page arguments ' = = Array (' Qianfeng_add ', 1),
' File ' = ' videocloud_qianfeng.pages.inc ',
' Access callback ' = ' user_is_logged_in ',
' Weight ' =-10,
' Type ' = Menu_callback,
);
Creating a FORM Element
$barcode _image as the picture path
function Qianfeng_add ($form, $form _state, $barcode _id) {
if (!empty ($barcode _image)) {
$form [' barcode_image_current '] = Array (
' #title ' and t (' Pictures '),
' #prefix ' = ' l ' (' ', $barcode _image, Array ("html" = True),
' #weight ' = 3,
);
}
$form [' barcode_image '] = Array (
' #type ' = ' file ',
' #name ' = ' barcode_image ',
' #required ' = False,
' #weight ' =>4
);
$form [' submit '] = Array (
' #title ' and T (' submit '),
' #type ' = ' Submit ',
' #value ' = ' Submit ',
' #weight ' =>5
);
$form [' #attributes '] [' enctype '] = ' multipart/form-data ';
return $form;
}
Form submission function
function Qianfeng_add_submit ($form, $form _state) {
$TP = Array ("GIF", "JPG", "PNG", "BMP");
$file = $_files["Barcode_image"];
if (!empty ($file [' name '])) {
$path = "./sites/default/files/barcode/";
if (!file_exists ($path)) {
mkdir ($path, 0777,true);
}
$name = MD5 (Time (). Rand (1,10000));
$fname = $file [' name '];
$ftype =explode ('. ', $fname);
$picName = $path. $name. '. $ftype [1];
if (!in_array ($ftype [1], $TP)) {
Drupal_set_message ("The picture is in the wrong format, the correct format (gif,jpg,png,bmp)!" ", ' warning ');
return false;
}
if (Intval ($file [' size ']) >2097152) {
Drupal_set_message ("Picture size exceeds 2M, please upload 2M below the picture!") ", ' warning ');
return false;
}
$id = Move_uploaded_file ($file [' Tmp_name '], $picName);
$fields [' image_name '] = $name. '. '. $ftype [1];
$fields [' image_path '] = "sites/default/files/barcode/";
}
}
Image upload in Drupal form