Skip to: site menu |main content

Welcome to my personal site. If You have any question or suggestion please feel free to contact me from contact page.

Advertisements

Contact me to place your Ads Here..

Powered by Drupal, an open source content management system

Syndicate

Syndicate content

File Save Upload for Drupal 6 users Accessing $_FILES is not prefered in drupal

1 reply [Last post]
inder's picture
Offline
Joined: 06/23/2009
File Save Upload for Drupal 6 users Accessing $_FILES is not prefered in drupal

In drupal 6 you can use file_save_upload() function for saving your uploaded files.Instead of mannually accessing $_FILES drupal standard is prefered.

<?php
file_save_upload
($source, $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_RENAME);
?>

For making your custom form to work for file upload you need to set Enctype for your form in following manner:-

<?php
$form
['#attributes'] = array('enctype' => "multipart/form-data");
?>

inder's picture
Offline
Joined: 06/23/2009
Drupal 5 methods for file_save_upload

Nothing has changed since Drupal 5 there, but the changes come in the submit function:

<?php
function upload_form_submit($form, &$form_state) {
 
//define your limits for the submission here
 
$limits = array ( ... ) ;
 
$validators = array(
   
'file_validate_extensions' => array($limits['extensions']),
   
'file_validate_image_resolution' => array($limits['resolution']),
   
'file_validate_size' => array($limits['file_size'], $limits['user_size']),
  );
 
// Save new file uploads.
 
if ($file = file_save_upload('file_upload', $validators, file_directory_path())) {
   
// Do something with $file here.
 
}
}
?>

Back to top

Related Pictures

Tags for File Save Upload for Drupal 6 users Accessing $_FILES is not prefered in drupal

Recent comments

InderSingh.com v1.2
(May 21, 2012)