1

In my project, customer can upload their products from the user dashboard ( not from super admin dashboard). I have made a product upload form where customer can upload their product or items. I am able to save all the product information through custom form. However, I am unable to upload the product images. I have gone through this post

https://stackoverflow.com/questions/8456954/magento-programmatically-add-product-image unable to uploade it

I have tired the code as after saving product information thru form :

$filename = $_FILES['image']['name'];

        $mediaArray = array(
            'thumbnail'   => $filename,
            'small_image' => $filename,
            'image'       => $filename,
        );

        // Remove unset images, add image to gallery if exists
        $importDir = Mage::getBaseDir('media') . DS . 'import'.DS;

        foreach($mediaArray as $imageType => $fileName) {
        echo    $filePath = $importDir.$fileName;

    $productData->addImageToMediaGallery($filePath, $imageType, false, false);

          }
     }

It shows the error as :

There has been an error processing your request. Image does not exist.

  • I'm not 100% sure what you are trying to do. Could you explain in a little more detail on what you are trying to do (and maybe some screenshots)? Are you trying to allow users/customers to upload product images? – kab8609 Sep 4 '13 at 18:11
  • In my project, customer can upload their products from the user dashboard ( not from super admin dashboard). I have made a product upload form where customer can upload their product or items. I am able to save all the product information through custom form. However, I am unable to upload the product images. I have gone through this post stackoverflow.com/questions/8456954/… unable to uploade it – MagentoBoy Sep 6 '13 at 6:36
  • Did you use file_exists in your loop to verify that the file actually exists? In the code you've posted it doesn't show the upload file being placed there so the issue might be before actually assigning the image. – Sander Mangel Sep 7 '13 at 5:43
  • @SanderMangel .. Hi thanks for your response :).. Yes, I have tried before but it is not getting into the loop so I thought to skip the loop and tried directly for the test. I have done echo of the path itself bt it is the correct but it is showing the same error. "There has been an error processing your request. Image does not exist." I have uploaded the image bt it is showing that image does not exist. I have checked path and the image it is correct :( – MagentoBoy Sep 7 '13 at 5:53
  • Any one here :( – MagentoBoy Sep 10 '13 at 6:25
2

There's likely a small issue with the file path somewhere in there. I know that you said you echo'd it out, but you may be missing something like perhaps a leading slash that shouldn't be there, etc.

One little thing I like to do to be 100% sure when inspecting this kind of thing, is to copy the file path, open up terminal, go to the Magento root, then ls <pasted_value> - that way you know for sure if the path is right or not.

The error message that you're seeing is originating in:

Mage_Catalog_Model_Product_Attribute_Backend_Media::addImage()
{
    ...
    if (!$file || !file_exists($file)) {
        Mage::throwException(Mage::helper('catalog')->__('Image does not exist.'));
    }
| improve this answer | |
  • @Kalenjordn... Thank you very much for showing me one more good way to dubugg the code. However, I found the solution. I was mistaking in understading of addImageToMediaGallery() function. For the product image first of all we need to upload the image somewehere or in media folder then the same this function will add the images in gallery. So, I used simple php function "move_uploaded_file()" to upload the picture in media file then I used addImageToMediaGallery() function to add those images in media gallery. Thank you all :) – MagentoBoy Sep 20 '13 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.