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 7644421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:41:04+00:00 2026-05-31T09:41:04+00:00

I have a custom module and I want a field to upload a picture.

  • 0

I have a custom module and I want a field to upload a picture. Chrome appears to upload the file, but it’s not working and I get the error below. Can someone please point me in the right direction?

function nafa_adoption_form($form_state)
{
  $form['#attributes'] = array('enctype' => "multipart/form-data");

  ...

  $form['picture'] = array(
    '#type' => 'file',
    '#title' => t('Picture'),
    '#size' => 20,
    '#upload_location' => 'public://uploads'
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );




  return $form;
}

Submit function:

function nafa_adoption_form_submit($form, &$form_state) 
{


  dvm($form_state['values']); //field 'picture' is blank

  $file = file_load($form_state['values']['picture']);

  $file->status = FILE_STATUS_PERMANENT;

  file_save($file);

  $fileid = file_load($file);

  variable_set('adoption_picture', $fileid->uri);

  if ($file)
  {
    drupal_set_message("File uploaded ");
  }

  else
  {
    drupal_set_message("File could not be uploaded");
  }

  drupal_set_message(t('Your form has been saved.'));
}

I also get the following error:

Notice: Undefined property: stdClass::$uri in file_save() (line 573 of /home/amn7940/nafa.achristiansen.com/includes/file.inc).
  • 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-05-31T09:41:05+00:00Added an answer on May 31, 2026 at 9:41 am

    If you look at the docs for the file element type you’ll notice there is no #upload_location property. This is because when using a file type you are expected to move the temporary file into the permanent location yourself.

    From the code you’re using in your submit function I’m pretty sure you’re looking for the managed_file type. If you use that instead your code should start working perfectly:

    $form['picture'] = array(
      '#type' => 'managed_file',
      '#title' => t('Picture'),
      '#size' => 20,
      '#upload_location' => 'public://uploads'
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a PyroCMS custom module, but now I want to add WYSIWYG
I am working on activecollab custom module, so have some problem in css file
I have make custom module in which I have make observer file. the observer
I am new to DNN and working with custom module in DNN, I have
I have a custom module, in which I want to load some use related
I have a custom 'Player' node type in Drupal with a CCK file field
I have been working on a custom module for Magento (ver. 1.8.0.0) that shows
I'm working on building a custom module in Orchard CMS, and I have the
I have a custom module I'm writing, part of what I want it to
I have a custom module I made for Magento. From the admin, there is

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.