UPload Single File In Magento

Upload Single file in Magento



<?php

/* UPLOAD FILE IN MAGENTO  [filename = name of file ]*/  


 if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '')
                    {
                        try
                        {    
                            $path = Mage::getBaseDir('media').DS."vendorplace/uploadedfiles/uploadfiles".DS; //desitnation directory where upload files are saved
                            $fname = $_FILES['filename']['name']; //file name  comes out

                            // echo "<pre>++++";
                            // print_r($fname);
                            // exit();

                            $uploader = new Varien_File_Uploader('filename'); //load class


                         


                            $uploader->setAllowedExtensions(array('csv','pdf','doc','docx','png','jpeg','jpg','gif','txt')); //Allowed extension for file
                            $uploader->setAllowCreateFolders(true); //for creating the directory if not exists
                            $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory.
                            $uploader->setFilesDispersion(false);
                            $uploader->save($path,$fname); //save the file on the specified path
                         
                        }
                        catch (Exception $e)
                        {
                            echo 'Error Message: '.$e->getMessage();
                        }
                    }
                 
                       $model->setFilename($fname);      /*Set Name of file in table field*/

                       $model->save();


?>

Comments

Popular posts from this blog

Get Swatch Text Product id of Configurable Product in Detail Page through Jquery Magento2

Get Customer Address with customer ID programmatically Magento2

programmaticlly Create Order in Magento2 with custom options in order