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

illSleepWheniDie’s picture

Hi mate,

I sent you a pm. I'm interested to know if/how you solved it.

Cheese
Alex

shady_gun’s picture

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

illSleepWheniDie’s picture

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 :)

function form_themer_user($op, &$edit, &$account, $category = NULL){
	if($op == 'after_update' || $op =='insert'){
		form_themer_make_all_image_presets($edit['picture']);
	}
}

function form_themer_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
	if($op == 'prepare'){
		$image_mimes = array('image/jpeg', 'image/png', 'image/gif');
		$mime = $node->filemime;
		$path = $node->destination;

		if(in_array($mime, $image_mimes)){
			form_themer_make_all_image_presets($path);
		} 
	}
}

shady_gun’s picture

Anyways try this

$file = $node->file;
$filename = $file->filename;

regards

illSleepWheniDie’s picture

Drupal 6 .. your code above is for a file attached to a node?

Cheese
Alex

shady_gun’s picture

what are you using for file upload?? cck file upload or upload module in drupal??

garima singh’s picture

 $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);
  }

garima singh’s picture

how get uploaded file name

garima singh’s picture

 $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