Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:24:34+00:00 2026-06-18T09:24:34+00:00

I found multiple drupal and stackoverflow pages with examples of upload forms, but I

  • 0

I found multiple drupal and stackoverflow pages with examples of upload forms, but I wasn’t able to get one to work. here I have included all the code I used, sort of parsing together what other people have done. I have included a menu, a form, a submit, and validate function. The upload file doesn’t save in the sites –> default –> file folder, and the submit set_message isn’t displayed upon submit. Why doesn’t this work?

<?php

function upload_example_menu() {
  //$items = array();
  $items['upload_example'] = array(
    'title' => t('Upload'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('upload_example_form'),
    'description' => t('uploading'),
    "access callback" => TRUE,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function upload_example_form() {
  $form['#attributes'] = array('enctype' => "multipart/form-data");
  $form['upload'] = array('#type' => 'file');
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );

  return $form;
}

function upload_example_form_validate($form, &$form_state) {
  if(!file_check_upload('upload')) {    
    form_set_error('upload', 'File missing for upload.');
  }
}

function upload_example_form_submit($form, &$form_state) {
    $validators = array();
    $file = file_save_upload('upload', $validators, file_directory_path());
    file_set_status($file, FILE_STATUS_PERMANENT);
    drupal_set_message(t('The form has been submitted.'));
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:24:35+00:00Added an answer on June 18, 2026 at 9:24 am

    Sorry I had many comments added to the answer but could not collect them into a reply like this.

    I see you have many changes made since the first page. Copying and changing it to a final answer…
    This code does not contain any critical fixes. What you have in the question now should be working. I just compared yours with a module I had for Drupal 6. However it requires some changes to best practices. See inline comments.

    <?php
    function upload_example_menu() {
      $items = array();
      $items['upload_example'] = array(
        'title' => 'Upload', // You don't use t() for menu router titles. See 'title callback' that defaults to t().
        'page callback' => 'drupal_get_form',
        'page arguments' => array('upload_example_form'),
        'description' => t('uploading'),
        'access arguments' => array('administer nodes'), // Users with administer nodes permission can access this form. Change it to a suitable one other than setting it TRUE blindly.
        'type' => MENU_CALLBACK,
      );
    
      return $items;
    }
    
    function upload_example_form() {
      $form['#attributes'] = array('enctype' => "multipart/form-data"); // Not necessary for D7.
      $form['upload'] = array(
        '#type' => 'file',
        '#title' => t('File'), // this is usually necessary.
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'), // t()
      );
    
      return $form;
    }
    
    function upload_example_form_validate($form, &$form_state) {
      if(!file_check_upload('upload')) {    
        form_set_error('upload', t('File missing for upload.')); // t()
      }
    }
    
    function upload_example_form_submit($form, &$form_state) {
        $validators = array();
        $file = file_save_upload('upload', $validators, file_directory_path());
        file_set_status($file, FILE_STATUS_PERMANENT);
        drupal_set_message(t('The form has been submitted.'));
    }
    ?>
    

    Let us know how it went 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/ UPDATE person
I'm using the jQuery multi-file upload plugin found here: http://www.fyneworks.com/jquery/multiple-file-upload/ I don't see in
I used the drupal example email module (email_example) found here: http://drupal.org/project/examples I'd like to
I have found multiple posts on stackoverflow regarding how to fix this but none
I've found multiple solutions to this problem, but none of them seem to work
Most examples shows multiple ratings I want to show ratings in Google but all
I've searched around and found multiple answers for this, but none of them have
I found this post that shows how to pass multiple check box selections to
I have recently found out that no argument constructor and multiple argument constructor cannnot
I have used multiple activities to handle mutiple views in android . I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.