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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:04:58+00:00 2026-06-10T06:04:58+00:00

I am making an application in which i am uploading file from my custom

  • 0

I am making an application in which i am uploading file from my custom tab as follows

enter image description here

i created a observer for event called catalog_product_save_after. In the particular function, i am uploading those files to catalog/product folder and its get uploaded to those folder without any error.

But when i am trying to assign those images to that particular product, i got the following error.
File was not uploaded at file E:\xampp\htdocs\magento\lib\Varien\File\Uploader.php on line 152

If i check system.log then i see the 2012-08-24T11:33:15+00:00 ERR (3): User Error: Some transactions have not been committed or rolled back in E:\xampp\htdocs\magento\lib\Varien\Db\Adapter\Pdo\Mysql.php on line 3645 this error.

My observer function is as follows

public function Savedata($observer)
    {
        $params     =   Mage::app()->getRequest()->getParams();

        $product    =   $observer->getEvent()->getProduct();

        $product_id =   $product->getId();


        $filesData  =   array();


        $keysData   =   array_keys($_FILES);


        foreach($keysData as $keys)
        {
            $uploader = new Varien_File_Uploader("$keys");
            $uploader->setAllowedExtensions(array('jpeg', 'jpg', 'png', 'tiff'));
            $uploader->setAllowRenameFiles(true);
            $uploader->setFilesDispersion(false);

            $path = Mage::getBaseDir('media') . DS  . "catalog" . DS . "product";

            if(!is_dir($path))
            {
                mkdir($path);
            }

            $extension  =   pathinfo($_FILES["$keys"]['name'], PATHINFO_EXTENSION);

            $date = new DateTime();

            $file_name                  =   $keys . "_" . $product_id . "." . $extension;

            $_FILES["$keys"]['name']    =   $file_name;

            $uploader->save($path, $_FILES["$keys"]['name']);
            $filesData[]    =   $path .DS. $_FILES["$keys"]['name'];
        }

        print_r($filesData);
        ///till this works file.. when i add following code, program dies. 

        try 
        {
            $productData = Mage::getModel('catalog/product')->load($product_id);

            print_r($productData->getData());


            foreach($filesData as $file)
            {
                $productData->addImageToMediaGallery($file, "image" ,false, false);
            }
            $productData->save();

            $productData = Mage::getModel('catalog/product')->load($product_id);

            print_r($productData->getData());
        }
        catch (Exception $e)
        {
            echo $e->getMessage() . "||" . $e->getCode() . "||" . $e->getFile() . "||" . $e->getLine();
        }


        exit();
    }

any suggestion where i am going wrong? why this error occur?

i am using magento 1.7

  • 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-10T06:05:00+00:00Added an answer on June 10, 2026 at 6:05 am

    I see that you’re going to update your catalog/product object when you’re saving it.

    You are using event catalog_product_save_after.

    Inside the observer, you call:

    $productData = Mage::getModel('catalog/product')->load($product_id);
    ...
    $productData->save();
    

    $productData is catalog/product object -> you saved it.

    You can guess what will happen, it will trigger event catalog_product_save_after and so on, looping forever.

    I see that you call $productData->save(); because in this event, the value has been saved and can not be changed.

    So instead of using catalog_product_save_after, you can use catalog_product_save_before.

    The same like your code, but remove $productData->save(); because it will automatically call save.

    Mage_Core_Model_Abstract
    
    public function save()
    {
        /**
         * Direct deleted items to delete method
         */
        if ($this->isDeleted()) {
            return $this->delete();
        }
        if (!$this->_hasModelChanged()) {
            return $this;
        }
        $this->_getResource()->beginTransaction();
        $dataCommited = false;
        try {
            $this->_beforeSave();
            if ($this->_dataSaveAllowed) {
                //see this line below, it will call save, so you don't need to call save in your `catalog_product_save_before` (no looping forever)
                $this->_getResource()->save($this);
                $this->_afterSave();
            }
            $this->_getResource()->addCommitCallback(array($this, 'afterCommitCallback'))
                ->commit();
            $this->_hasDataChanges = false;
            $dataCommited = true;
        } catch (Exception $e) {
            $this->_getResource()->rollBack();
            $this->_hasDataChanges = true;
            throw $e;
        }
        if ($dataCommited) {
            $this->_afterSaveCommit();
        }
        return $this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an application which uses MANY images. The application gets the images from
I am making a qt application which allows the user to select a file
I am making an application which is using birthday from contacts of device.I am
I am making an application which will retrieve all mailboxes from Domino Server. And
I am making an application which takes image from the camera and then email
I am making an application which Streams media from the Internet,it can be from
What I am doing right now I am making an application which is uploading
i am making an application which first compresses a file and then transfer it.
I am making an application which will do something on receipt of a particular
I am making an application in which I have to show video from assets

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.