<input type="file" name="image">
Select path of media directory
$path = Mage::getBaseDir() . DS . 'media' . DS . 'customerimages' . DS;
$imagename = $this->uploadImageFile($_FILES, $path);
Create functions
function uploadImageFile($filedata, $path){
if(isset($filedata['image']) && $filedata['image']['error'] == 0){
try{
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
if(!is_dir($path)){
mkdir($path, 0755, true);
}
$ext = pathinfo($filedata['image']['name'], PATHINFO_EXTENSION);
$uploader->save($path, date('Ymd') . "_" . date('his') . '.' . $ext);
$uploadFile = $uploader->getUploadedFileName();
if($uploadFile){
return $uploadFile;
} else {
return 'File not uploaded!';
}
} catch (Exception $e) {
return $e->getMessage();
}
} else {
return 'Please select image file!';
}
}
No comments:
Post a Comment