I am working on image upload by custom module. In this module if I upload image named

Screenshot (1).jpg

When file get upload it saved with name


Because of this image didnt get showed on website. Below is code for uploading image.

if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
            try {   
                /* Starting upload */
                $uploader = new Varien_File_Uploader('filename');

                // Any extention would work

                // Set the file upload mode 
                // false -> get the file directly in the specified folder
                // true -> get the file in the product like folders 
                //  (file.jpg will go in something like /media/f/i/file.jpg)

                // We set media as the upload dir
                $path = Mage::getBaseDir('media')."/home/sectionzero/" ;
                $uploader->save($path, $_FILES['filename']['name'] );

            } catch (Exception $e) {


            //this way the name is saved in DB
            $data['filename']['value'] = "home/sectionzero/".$_FILES['filename']['name'];

Please help me to resolve this.

1 Answer 1


This is the normal behaviour of the uploader. Files should not have spaces in the name. You should save the filename after the upload and not before since the file's name before and after uploading will differ.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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