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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:32:44+00:00 2026-06-06T22:32:44+00:00

I am new to magento and i am Creating Custom module for File upload

  • 0

I am new to magento and i am Creating Custom module for File upload in magento admin.

Right now i have post the upload file in my module controller.
Here i have used move_uploaded_file to upload file in same directory with in controller folder.
below code i have used for file upload in controller

$file_name=$_FILES["file"]["name"];
    $file_path="import/$file_name";

    if(move_uploaded_file($_FILES["file"]["tmp_name"],$file_path))
    {
        // my files not uploading 
    }

I can’t able to upload the file in directory folder.

So what i am doing wrong? or suggest me if using move_uploaded_file in magento controller is correct way to handle file upload ?

Thanks.

  • 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-06T22:32:45+00:00Added an answer on June 6, 2026 at 10:32 pm

    In order to upload file in Magento, you can use Varien_File_Uploader::save() method as:

    if(isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') {
        try {
            $fileName       = $_FILES['file']['name'];
            $fileExt        = strtolower(substr(strrchr($fileName, "."), 1));
            $fileNamewoe    = rtrim($fileName, $fileExt);
            $fileName       = str_replace(' ', '', $fileNamewoe) . '.' . $fileExt;
    
            $uploader       = new Varien_File_Uploader('file');
            $uploader->setAllowedExtensions(array('png', 'jpg')); //allowed extensions
            $uploader->setAllowRenameFiles(false);
            $uploader->setFilesDispersion(false);
            $path = Mage::getBaseDir('media') . DS . 'yourModuleFolder';
            if(!is_dir($path)){
                mkdir($path, 0777, true);
            }
            $uploader->save($path . DS, $fileName );
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a new custom extension for magento admin section. Main menu option
I am creating a custom module for a Magento ecommerce site, and the module
I am new to Magento. I need two table in my custom module and
i'm starting with magento, and i'm creating a new module that uses widgets. i
New to magento here, I have figured out how to use my local.xml to
I am new to Magento CMS, i have configured products using admin panel, at
Right now when Magento sends new account confirmation, order details, etc. to customers, it
I am creating a module to add banners. Now I have a problem when
Thanks in advance. I am new to Magento, and I have created a module
I have a Observer class where i was always used to set new magento

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.