Posted by wa2nlinux on June 11, 2010 at 1:54pm
I have build simple module form using form api to upload a txt document.
The txt document then process and convert to pdf document, a link to download pdf is given
here my code
function modulku_menu() {
$items = array();
$items['module/form'] = array(
'title' => t('My form'),
'page callback' => 'modulku_form',
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
);
return $items;
}
function modulku_form() {
return drupal_get_form('myform');
}
function myform() {
$form = array();
// If this #attribute is not present, upload will fail on submit
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file_upload'] = array(
'#title' => t('Upload file'),
'#type' => 'file',
);
$form['submit_upload'] = array(
'#type' => 'submit',
'#value' => 'Submit'
);
return $form;
}
function myform_submit($form, &$form_state) {
$validators = array();
$dest = 'upload_directory';
$file = file_save_upload('file_upload', $validators, $dest);
if ($file != 0) {
$random_digit=rand(0,9);
$new_file_name=$random_digit.$file->filename;
$dest_path = $new_file_name;
$result = file_copy($file, $dest_path, FILE_EXISTS_RENAME);
if ($result == 1) {
$path= $new_file_name;
//process and convert in here
$filepdf="$PATH/$name.pdf";
if (file_exists($filepdf)) {
echo "$filepdf created <BR/>";
echo "$filepdfF can be download it <a href=$name.pdf>here</a> <BR/>";
} else {
echo "The file $filepdf does not exist";}
}
else {
//Failure
}
}
else {
form_set_error('myform', t("Failed to save the file."));
}
}
?>The upload process is running well, and the converting process also work,
the question is how can I make the download link result is better than just plain hmtl
echo "$filepdf created <BR/>";
echo "$filepdfF can be download it <a href=$name.pdf>here</a> <BR/>";
I mean, the result page also "inside" the drupal theme not only the plain html page
Regards
wa2nlinux