function _fillpdf_save_upload in FillPDF 7
Same name and namespace in other branches
- 7.2 fillpdf.admin.inc \_fillpdf_save_upload()
2 calls to _fillpdf_save_upload()
- fillpdf_forms_admin_submit in ./fillpdf.admin.inc
- Creates a new Form from the uploaded PDF, including parsed fields.
- fillpdf_form_edit_submit in ./fillpdf.admin.inc
- Submit Edit or Delete for existing PDF form.
File
- ./fillpdf.admin.inc, line 255
- Allows mappings of PDFs to site content.
Code
function _fillpdf_save_upload($form_key, $fid = NULL) {
if (isset($fid)) {
$action = FILE_EXISTS_REPLACE;
$destination = db_select('fillpdf_forms', 'ff')
->fields('ff', array(
'url',
))
->condition('ff.fid', $fid, '=')
->execute()
->fetchField();
}
else {
$action = FILE_EXISTS_RENAME;
$destination = fillpdf_build_uri('fillpdf');
}
$validators = array(
'file_validate_extensions' => array(
'pdf',
),
);
$file = file_save_upload($form_key, $validators);
$file = file_move($file, $destination, $action);
if ($file) {
drupal_set_message(t('<strong>@filename</strong> was successfully uploaded.', array(
'@filename' => $file->filename,
)));
$file->status = FILE_STATUS_PERMANENT;
$file = file_save($file);
if (!isset($fid)) {
db_insert('fillpdf_forms')
->fields(array(
'fid' => $file->fid,
'title' => $file->filename,
'url' => $file->uri,
'scheme' => fillpdf_template_scheme(),
))
->execute();
$fid = $file->fid;
file_usage_add($file, 'fillpdf', 'fillpdf_form', $fid);
}
fillpdf_parse_pdf($fid);
return $fid;
}
else {
drupal_set_message(t('Error saving file to @destination', array(
'@destination' => $destination,
)), 'error');
}
}