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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:19:47+00:00 2026-06-13T13:19:47+00:00

I am developing a custom module in which I want to: Upload an image

  • 0

I am developing a custom module in which I want to:

  1. Upload an image through a form.
  2. Move image from default folder to my desired folder.
  3. And finally display the image under the same form (below the submit button).

I’ve achieved the first goal by implementing hook_menu and hook_form but I am stucked very badly in the remaining two goals for last 3 days. Whenever I try to move uploaded image from default folder I get the error message of “Invalid location” and for the third point I didn’t understand what to do? I want when the user selects the image and submits the form the image is displayed on the same page under the submit button. Any help would be really appreciated. Here’s my code:-

function create_ad_form($form, &$form_submit)
{
   ...

   $form['image_file'] = array(
     '#title' => t('Upload Banner:'),
     '#type' => 'file'
   );

   $form['#attributes']['enctype'] = 'multipart/form-data';

   ...
}

function create_ad_form_submit($form, &$form_state)
{
    $module=drupal_get_path('module', 'create_ad');
    $validators = array();

    $file = file_save_upload('image_file', $validators,"public://",FILE_EXISTS_RENAME);

     if ($file)
 {
    $file->status=FILE_STATUS_PERMANENT;
    file_save($file);

    $result = file_unmanaged_copy($file, $module, FILE_EXISTS_RENAME);
    if ($result == 1)
    {


    }
    else
    {
      drupal_set_message('Couldn\'t copy file: '.$file->name);
    }
  }
  else
  {
    form_set_error('create_ad', t("Failed to save the file."));
  }
}
  • 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-13T13:19:49+00:00Added an answer on June 13, 2026 at 1:19 pm

    I’ve managed to display the image, however still can’t move the image to any folder so placed them in the default “public://” directory. Display image on the same page without ajax is discussed here: Drupal 7 FAPI- Adding form elements in validate or submit handlers and with ajax discussed here: Drupal 7 FAPI – ajax image preview

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

Sidebar

Related Questions

I'm developing a custom contacts app. I read default Contacts app source from Github
I'm developing a custom control that doesn't inherit from Button. I want to implement
I am developing a custom control derived from System.Windows.Controls.ContentControl. In the controls default template
I'm developing a custom module for Drupal 6, that creates a simple form. My
I'm developing a custom module for my Magento installation (version 1.6.2.0). I registered a
I'm developing a custom widget (inheriting from QWidget) to use as a control. How
I'm developing a custom control, which most resembles a text area. I am drawing
I am developing a custom shopping cart for which existing customers will need to
I'm currently developing a custom module and for some reason it appends a blank
I am developing custom components which fit into the Nimbus look and feel. I'm

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.