0

I want to upload image by custom module.In this module if i upload image the image name is

images (1).jpg

when image upload name saved it

images_1_.jpg

My code is

if (isset($_FILES['vendor_gallery']['name']) && $_FILES['vendor_gallery']['name'] != '') {
                try {
                    $path     = Mage::getBaseDir('media') . DS . 'vendors' . DS . 'profile';
                     $fname    = $_FILES['vendor_gallery']['name'];
                    $uploader = new Varien_File_Uploader('vendor_gallery'); 

                    $uploader->setAllowCreateFolders(false); 
                    $uploader->setAllowRenameFiles(false); 
                    $uploader->setFilesDispersion(false);
                    $uploader->save($path, $fname);                     
                }
                catch (Exception $e) {
                    echo 'Error Message: ' . $e->getMessage();
                }
            }


            if ($fname != "") {
                $data['vendor_gallery'] = $fname;
            }
            echo $fname;exit;

            try {
                $gallery = Mage::getModel('marketplace/gallery');
                if(isset($data['vendor_gallery']) && ($data['vendor_gallery'])!=''){
                $gallery->setData($data);
                $gallery->save();
                }

so how to do correct image name?

  • What is wrong with that image name? Magento has just normalised it. – Smartie Sep 16 '15 at 6:36
  • i get image name save in database images (1).jpg and the path url images_1_.jpg so i get currupt image – ABC Sep 16 '15 at 6:39
1

You can get the uploaded file by the following code.

$uploader->getUploadedFileName()
// Here $uploader is object of the Varien_File_Uploader class

This will return uploaded file name.

refer this link

0

You can change name of the image after this point:

$fname    = $_FILES['vendor_gallery']['name'];

You can play with $fname and change it accordingly. But be careful with spaces, they are not accepted at all.

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.