Last active
May 25, 2018 05:50
-
-
Save Niroshan3/964f62c0765a49deb4441ff0601523c8 to your computer and use it in GitHub Desktop.
Magento File Upload via Varien_File_Uploader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$uploader = new Varien_File_Uploader($_filename); | |
$uploader->setAllowedExtensions(array('zip','ZIP')); | |
$uploader->setAllowRenameFiles(true); //if true, uploaded file's name will be changed, if file with the same name already exists directory. Necessary to avoid conflicts | |
$uploader->setFilesDispersion(false); //To have a dispersion based on the original file name (as the file option does), we will have to do it manually | |
$uploader->setAllowCreateFolders(true); //for creating the directory if not exists | |
$extension = pathinfo(strtolower($_file['name']), PATHINFO_EXTENSION); | |
$fileName = Mage_Core_Model_File_Uploader::getCorrectFileName($_file['name']); | |
$dispersion = Mage_Core_Model_File_Uploader::getDispretionPath($fileName); // We get the dispersion manually here | |
$fileHash = md5(file_get_contents($_file['tmp_name'])); //here the secretkey | |
$path = $this->getOrderTargetDir() . $dispersion; | |
$DestName = $fileHash . '.' . $extension; | |
$result = $uploader->save($path, $DestName); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment