Skip to main content

Articles tagged with "upload"

Webform Protected Downloads

11th Mar 2024

I recently produced the first release of the Webform Protected Downloads module that is compatible with Drupal 10. It provides the ability for sites to have 'gated' content which users can download once they have filled out a form for their details. This can convert engaged visitors into leads, set up licenses for customers, or simply validate a user for access to a file. Put simply, as the project's description says, this module could be useful to you if:

  • You want to offer some files for download to either anonymous or registered users
  • You don't want those files to be...
Read more

File uploads in Drupal 6 - Part 1

21st Jan 2009

So you've got a nice new version of Drupal 6 and you're building a form, but you want to allow users to upload a file. Of course this is easy with Drupal, and we covered how to do just that, but for Drupal 5, in our previous article: Example code to build an upload form in Drupal. Here we show how file uploads are done in Drupal 6.

Honestly, not much has changed, here's the code to get your file upload element onto your form:


function build_upload_form(){
    $form['#attributes'] = array('enctype' => 'multipart/form-data');
    $form['file_upload'] = array(
        '#type' => 'file',
        '#title'...
Read more

Example code to build an upload form in Drupal

27th Mar 2007

Putting together an upload form in Drupal 5 is easier than you think - there are just a couple of things you need to remember ...

The form is built like this:


function build_upload_form(){
    $form['#attributes'] = array('enctype' => "multipart/form-data");
    $form['file_upload']=array('#type'=>'file','#title'=>'Filename');
    $form['submit']=array('#type'=>'submit','#value'=>'Upload file');
    return $form;
}

And the submit is handled like so, note - the value passed into file_check_upload is the name (terminal array key) of the form element defined in your form building function ...


function upload_form_submit() {
    $file = file_check_upload('file_upload');
    //handle the file, using file_save_upload, or something similar
    if ($file){
    $file = file_save_upload($file,'some_path');
    }
}

And thats it...

Read more