· 7 years ago · May 29, 2018, 10:48 PM
1<?php
2$uploader = new Varien_File_Uploader($_filename);
3$uploader->setAllowedExtensions(array('zip','ZIP'));
4$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
5
6$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
7$uploader->setAllowCreateFolders(true); //for creating the directory if not exists
8
9$extension = pathinfo(strtolower($_file['name']), PATHINFO_EXTENSION);
10
11$fileName = Mage_Core_Model_File_Uploader::getCorrectFileName($_file['name']);
12$dispersion = Mage_Core_Model_File_Uploader::getDispretionPath($fileName); // We get the dispersion manually here
13$fileHash = md5(file_get_contents($_file['tmp_name'])); //here the secretkey
14
15$path = $this->getOrderTargetDir() . $dispersion;
16$DestName = $fileHash . '.' . $extension;
17
18$result = $uploader->save($path, $DestName);
19
20?>