Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By shady_gun on
hi,
i want to get the filename of the file i uploaded.. how can i do it???
this is my file upload code
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['upload']['file'] = array(
'#type' => 'file',
'#title' => t('Upload file '),
'#size' => 40,
);
$form['upload']['submit'] = array(
'#type' => 'submit',
'#value' => t('Upload'),
);
return $form;
i need the filename of the above file upload
regards
Comments
hi
Hi mate,
I sent you a pm. I'm interested to know if/how you solved it.
Cheese
Alex
Yes, Sorry forgot to update status
Well first of all you have to upload the file .... After uploading the files you get the file details
here is the piece of code which may help you ..
this is my hook_form
$form['upload']['file'] = array(
'#type' => 'file',
'#title' => t('Attach Photo'),
'#prefix' => '
'#suffix' => '
',
);
and this is my hook_submit_form
$dir = variable_get('file_directory_path', 'sites/default/files') . '/photos';
$save = file_save_upload('file', array(), $dir, true);
$filename = $save->filename;
hope this helps ...
regards
I see
Thanks for the fast reply!
So your form is a custom upload form with custom upload handler. My requirement was slightly different,
I had to modify all uploads to trigger imagecache after each upload was done.
What I did was to use hook_nodeapi() and hook_userapi() to catch all the photo album uploads and user profile uploads. Here's the sample piece of code, pls feel free to comment :)
Ok, are you using drupal 6 or 5??
Anyways try this
regards
Hi Shady
Drupal 6 .. your code above is for a file attached to a node?
Cheese
Alex
yes ..
what are you using for file upload?? cck file upload or upload module in drupal??
Code of upload image
$file = file_save_upload('upload_image', array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array('1000x1000', '100x100'),
), 'public://upload/photoLayout/', FILE_EXISTS_RENAME);
if ($file != NULL) {
$imagename = ($file->getFilename());
$imagesize = intval($file->getSize() / 1000) . ' kb';
$file->setPermanent();
/* Save the file in database */
$file->save();
drupal_set_message('Filename: ' . $imagename);
}
still problem is not solved
how get uploaded file name
this is my code of uploading image
$file = file_save_upload('upload_image', array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array('1000x1000', '100x100'),
), 'public://upload/photoLayout/', FILE_EXISTS_RENAME);
if ($file != NULL) {
$imagename = ($file->getFilename());
$imagesize = intval($file->getSize() / 1000) . ' kb';
$file->setPermanent();
/* Save the file in database */
$file->save();
drupal_set_message('Filename: ' . $imagename);
}
but problem is not solved still