I've been trying to find a way to add Photo to a customer profile in Magento. They have everything but this, and I can't find anywhere how to do it. Any help is appreciated. I'm using Community edition.
Asked
Active
Viewed 5,835 times
1 Answers
3
To upload profile photo for customer in magento we need to follow few steps as below.
- Add a new field for profile photo(How to create new fields for customer - Check this link it will helps you).
The above link helps you to add a new filed in DB and you need to upload that photo manually the below code will helps you to upload photos in magento.
if(isset($_FILES['logo']['name']) and (file_exists($_FILES['logo']['tmp_name']))) { try { $uploader = new Varien_File_Uploader('logo'); $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS .'catalog/customer/logo/'; $newName = time() . $_FILES['logo']['name']; $uploader->save($path, $newName); $customer->setLogo($newName); // actual path of image $imageUrl = $path . $newName; // path of the resized image to be saved // here, the resized image is saved in media/resized folder $imageResized = $path . $newName; // resize image only if the image file exists and the resized image file doesn't exist // the image is resized proportionally with the width/height 135px if (!file_exists($imageResized)&&file_exists($imageUrl)) : $imageObj = new Varien_Image($imageUrl); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE); $imageObj->resize(150, 150); $imageObj->save($imageResized); endif; }catch(Exception $e) { } }
After upload we need to save file name in DB.
$customer->setLogo($newName);

Community
- 1
- 1

Sankar Subburaj
- 4,992
- 12
- 48
- 79
-
Hi Sankar. Thanks for the solution! I've put the code into my module's observer but whenever 'customer_save_before' or 'customer_save_after' event fires(within customer back-end) $_FILES array is empty. I get file name in $_POST array though but i don't get the $_FILES. Any ideas? Maybe you can suggest other place where I could put this code? – Alan Sep 03 '14 at 13:28
-
Ok, I got this. "Additional information" form needs enctype="multipart/form-data" attribute. Otherwise it won't submit files. – Alan Sep 03 '14 at 14:28