Monthly Archive for April, 2011

Free Transform Manager As3 v1.3

This is an update to my earlier post announcing the launch of FTM. Source provided after the jump.

Continue reading ‘Free Transform Manager As3 v1.3′

Drupal 7 – Handling file uploads

When trying to deal with custom forms with file upload fields, you may sometimes get a error regarding extensions:

The specified file “your file name here” could not be uploaded. Only files with the following extensions are allowed: “jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp”

To allow all extensions, you have to manually set the ‘file_validate_extensions’ validator to an empty array.

e.g.
$validators = array('file_validate_extensions' => array());
$file = file_save_upload('upload', $validators);

For more information, check out Drupal API’s documentation at http://api.drupal.org/api/drupal/includes–file.inc/function/file_save_upload/7

The bare requirements for a file upload form is the “multipart/form-data” enctype, a “file” field, and the standard “submit” button. An example of a basic structure:


$form ['upload'] = array (
'#type' => 'file',
'#title' => 'Choose file',
'#description' => 'Upload a file.' );
$form ['submit'] = array ('#type' => 'submit', '#value' => t ( 'Submit' ) );
$form ['#attributes'] = array ('enctype' => "multipart/form-data" );