Just a continuation of my study about Magento Admin Grid. I'm trying to create a File Upload and I am successfully made it. However, I'm encountering a problem regarding the update and delete of the file upload form field. The other input form fields are populated with data and can be updated and deleted from the records.
Problem:
When tried to update the records, the file upload field was not displaying the name of the uploaded file, and when try to update it, the old uploaded file was not deleted but the file path was updated on the records.
When try to delete the records, the uploaded file was not deleted but deleted on the record.
I also have minor issue regarding the grid. The grid is not displaying the ID of the records and other integer or number even if they were declared on the grid.
Question:
What am I missing in my update form fields and grid?
Here is a sample of my form fields.
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('pmadmin')->__('Matrix Title'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));
$fieldset->addField('file_path', 'file', array(
'label' => Mage::helper('pmadmin')->__('File'),
'value' => '',
'class' => 'required-entry',
'required' => true,
'disabled' => false,
'readonly' => true,
'name' => 'file_path',
));
$fieldset->addField('short_description', 'text', array(
'label' => Mage::helper('pmadmin')->__('Short Description'),
'class' => 'required-entry',
'required' => true,
'name' => 'short_description',
));
Here is my controller
public function editAction()
{
$pmadminId = $this->getRequest()->getParam('id');
$pmadminModel = Mage::getModel('pmadmin/pmadmin')->load($pmadminId);
if ($pmadminModel->getId() || $pmadminId == 0) {
Mage::register('pmadmin_data', $pmadminModel);
$this->loadLayout();
$this->_setActiveMenu('pmadmin/items');
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
$this->_addContent($this->getLayout()->createBlock('pmadmin/adminhtml_pmadmin_edit'))
->_addLeft($this->getLayout()->createBlock('pmadmin/adminhtml_pmadmin_edit_tabs'));
$this->renderLayout();
} else {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('pmadmin')->__('Item does not exist'));
$this->_redirect('*/*/');
}
}
public function newAction()
{
$this->_forward('edit');
}
public function saveAction() {
$post_data=$this->getRequest()->getPost();
if ($post_data) {
try {
//save file to the destination folder
if (isset($_FILES)){
if ($_FILES['file_path']['name']) {
$path = Mage::getBaseDir('media') . DS . 'rts' . DS .'pmadmin'.DS;
$uploader = new Varien_File_Uploader('file_path');
$uploader->setAllowedExtensions(array('PDF','pdf'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path.$_FILES['file_path']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
$post_data['file_path']='rts/pmadmin/'.$filename;
}
}
//save file path to the database
$model = Mage::getModel("pmadmin/pmadmin")
->addData($post_data)
->setId($this->getRequest()->getParam("id"))
->save();
Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("File was successfully saved"));
Mage::getSingleton("adminhtml/session")->setPmadminData(false);
if ($this->getRequest()->getParam("back")) {
$this->_redirect("*/*/edit", array("id" => $model->getId()));
return;
}
$this->_redirect("*/*/");
return;
}
catch (Exception $e) {
Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
Mage::getSingleton("adminhtml/session")->setPmadminData($this->getRequest()->getPost());
$this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id")));
return;
}
}
$this->_redirect("*/*/");
}
public function deleteAction()
{
if( $this->getRequest()->getParam('id') > 0 ) {
try {
$pmadminModel = Mage::getModel('pmadmin/pmadmin');
$pmadminModel->setId($this->getRequest()->getParam('id'))
->delete();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
$this->_redirect('*/*/');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
}
}
$this->_redirect('*/*/');
}
Note:
I am able to successfully update other form fields and the file path from the records but not the file uploaded.
you have to add else statment if the user is not uploading for the edit. $postdata['file_path']['value'] this is created by magento automatically.
if (isset($_FILES)){
if ($_FILES['file_path']['name']) {
$path = Mage::getBaseDir('media') . DS . 'rts' . DS .'pmadmin'.DS;
$uploader = new Varien_File_Uploader('file_path');
$uploader->setAllowedExtensions(array('PDF','pdf'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$destFile = $path.$_FILES['file_path']['name'];
$filename = $uploader->getNewFileName($destFile);
$uploader->save($path, $filename);
$post_data['file_path']='rts/pmadmin/'.$filename;
}
else {
$postdata['file_path']=$postdata['file_path']['value'];
}
}
Related
I would like some help uploading two images in my module
my controller looks like this:
if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
try {
$uploader = new Varien_File_Uploader('filename');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS ;
$uploader->save($path, $_FILES['filename']['name'] );
} catch (Exception $e) {
}
$data['filename'] = $_FILES['filename']['name'];
}
if(isset($_FILES['filename_mobile']['name']) && $_FILES['filename_mobile']['name'] != '') {
try {
$uploader = new Varien_File_Uploader('filename_mobile');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media').DS.'mobile'.DS;
$uploader->save($path, $_FILES['filename_mobile']['name'] );
} catch (Exception $e) {
}
$data['filename_mobile'] = $_FILES['filename_mobile']['name'];
}
and my form is like this:
$fieldset->addField('filename', 'image', array(
'label' => Mage::helper('configuracao')->__('Banner Desktop'),
'required' => false,
'name' => 'filename',
));
$fieldset->addField('filename_mobile', 'image', array(
'label' => Mage::helper('configuracao')->__('Banner Mobile'),
'required' => false,
'name' => 'filename_mobile',
));
when I save, the database is "Array" and the thumbnail also says "Array"
where am i wrong could someone please help me?
Attempting to generate thumbnails with Image_moo & CodeIgniter framework. Image_moo does not output any errors, however, thumbnail images are never generated.
dir structure
app
- controllers/
Admin.php
...
- libraries/
Image_moo.php
...
- models/
Admin_photos_model.php
Admin.php
public function photo_upload() {
$rules = [
[
'field' => 'caption',
'label' => 'Caption'//,
//'rules' => 'required'
],[
'field' => 'description',
'label' => 'Description'//,
//'rules' => 'required'
],[
'field' => 'series',
'label' => 'Series',
'rules' => 'required'
]
];
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == FALSE) {
$this->load->view('admin/photos/upload');
} else {
$series = str_replace(' ', '', strtolower($_POST['series']));
$upload_path = './img/photos/'.$series.'/';
$config = [
'upload_path' => $upload_path, //'./img/photos/'.$series.'/',
'allowed_types' => 'gif|jpg|jpeg|png'
];
$this->load->library('upload', $config);
if (!file_exists($upload_path)) { //check if series dir exists
mkdir($upload_path, 0777, true); // create dir if !exist
$num = 1; //init
} else {
$num = $this->db->where('series', $series)->count_all_results('photos') + 1;
};
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/photos/upload', $error);
} else {
$file = $this->upload->data();
$caption = $_POST['caption'];
$description = $_POST['description'];
$data = [
'filename' => $file['file_name'],
'series' => $series,
'num' => $num,
'caption' => $caption,
'description' => $description
];
$this->Admin_photos_model->upload($data);
$this->load->library('image_moo'); //create thumbnail, upload
$file_raw_name = $this->upload->data('raw_name');
$file_ext = $this->upload->data('file_ext');
$file_width = $this->upload->data('image_width');
$file_height = $this->upload->data('image_height');
$file_uploaded = $upload_path.$data['filename']; //$field_info->upload_path.'/'.$uploader_response[0]->name;
if ($file_width > 1024 && $file_height > 720) {
$this->image_moo->load($file_uploaded)
->resize_crop(1024,720)->save($upload_path.$file_raw_name.'_thumb_xl'.$file_ext)
->resize_crop(800,562)->save($upload_path.$file_raw_name.'_thumb_lg'.$file_ext)
->resize_crop(640,450)->save($upload_path.$file_raw_name.'_thumb_med'.$file_ext)
->resize_crop(450,316)->save($upload_path.$file_raw_name.'_thumb_sm'.$file_ext)
->resize_crop(222,156)->save($upload_path.$file_raw_name.'_thumb_xs'.$file_ext);
$data = [
'has_thumb_xl' => 1,
'has_thumb_lg' => 1,
'has_thumb_med' => 1,
'has_thumb_sm' => 1,
'has_thumb_xs' => 1,
'thumb_xl_filename' => $file_raw_name.'_thumb_xl'.$file_ext,
'thumb_lg_filename' => $file_raw_name.'_thumb_lg'.$file_ext,
'thumb_med_filename' => $file_raw_name.'_thumb_med'.$file_ext,
'thumb_sm_filename' => $file_raw_name.'_thumb_sm'.$file_ext,
'thumb_xs_filename' => $file_raw_name.'_thumb_xs'.$file_ext
];
};
if ($this->image_moo->error) {
print $this->image_moo->display_errors();
};
$this->Admin_photos_model->thumbnails($data);
$this->session->set_flashdata('message','file uploaded: '.$file_uploaded.'New image has been added..'.'series dir: '.$series.'last num of series: '.$num.'thumb:'.$file_raw_name.'_thumb_xl'.$file_ext.'errors: '.$this->image_moo->display_errors());
redirect('admin/photos');
};
Admin_photos_model
<?php
class Admin_photos_model extends CI_Model {
public function __construct(){
$this->load->database();
}
public function upload($data) {
try {
$this->db->insert('photos', $data);
return true;
} catch (Exception $e) {
echo $e->getMessage();
};
}
public function thumbnails($data) {
try {
$this->db->insert('photos', $data);
return true;
} catch (Exception $e) {
echo $e->getMessage();
};
}
}
Attempting to generate thumbnails, I'm separating the photos by series. If the series hasn't started, a new dir is created. Ideally, uploading 'waterfall.jpg' with series 'nature' would yield:
app
...
public_html/
img/
photos/
nature/
waterfall.jpg
waterfall_thumb_xl.jpg
waterfall_thumb_lg.jpg
waterfall_thumb_med.jpg
waterfall_thumb_sm.jpg
waterfall_thumb_xs.jpg
Any help would be appreciated.
Reading the image_moo documentation, the save function needs to have an overwrite=FALSE/TRUE. Doing so seemed to fix it.
"save($x,$overwrite=FALSE) - Saved the manipulated image (if
applicable) to file $x - JPG, PNG, GIF supported. If overwrite is not
set file write may fail. The file saved will be dependant on
processing done to the image, or a simple copy if nothing has been
done."
CakePHP 2.x: I am struggling with validating an image upload field in a form for adding users. The upload field is not manditory. But it validates the field always as false while the image is uploaded. It seems the whole validation is working partially. Any help would be appreciated
User.php model :
public $validate = array(
'picture' => array(
'required' => false,
'allowEmpty' => true,
'custom' => array(
'rule' => array('imageExist'),
'message' => 'There is already a picture with that name on the server'
)
));
// function to check if file already exists
public function imageExist($check) {
$picturename = $check['picture'];
$path = WWW_ROOT . 'userimages/';
$file = $path . $picturename;
if (file_exists($file)) {
return false;
} else {
return true;
}
}
add.ctp:
<?php
echo $this->Form->create('User', array('class' => 'form-horizontal', 'role' => 'form', 'div' => false, 'type' => 'file'));
echo $this->Form->input('username', array('label' => "Username"));
echo $this->Form->input('picture', array('label' => "Avatar", 'type' => 'file'));
echo $this->Form>formDefaultActions();
echo $this->Form->end();
?>
UserController.php:
public function add() {
if ($this->request->is('post')) {
$this->User->create();
// set picture and path
$filedir = WWW_ROOT . 'userimages/';
$file = $filedir . $this->request->data['User']['picture']['name'];
// upload avatar picture
move_uploaded_file(
$this->request->data['User']['picture']['tmp_name'],
$file
);
$this->request->data['User']['picture'] = $this->request->data['User']['picture']['name'];
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been added'), 'success' );
$this->redirect(array(
'action' => 'index'
));
} else {
$this->Session->setFlash(__('The user could not be created. Please, try again'), 'error' );
}
}
}
You need to check your validation before uploading or will be always false. If you upload your file, when cakephp validates your file already exists in folder.
You can just move your logic to something like:
$this->request->data['User']['picture'] = $this->request->data['User']['picture']['name'];
if ($this->User->save($this->request->data)) {
move_uploaded_file(
$this->request->data['User']['picture']['tmp_name'],
$file
);
}
Or check, before saving:
if ($this->User->validates()) {
if ($this->User->save($this->request->data)) {
move_uploaded_file(
$this->request->data['User']['picture']['tmp_name'],
$file
);
}
}
comment this
$this->request->data['User']['picture'] = $this->request->data['User']['picture']['name'];
and also take off the 2 statements into model, required and allowEmpty.also replace in your controller:
if ($this->User->save($this->request->data))
with
if ($this->User->save($this->request->data['User']))
and the pic name should be saved into the db
I'm working on multi file(images) uploading functionality.
I've tried everything I got.
It's not working.
It's uploading images on the path I specified but not inserting image's names on the table column.
The table's column name is "sample"
Here's the snippet of the view:
$this->widget('CMultiFileUpload', array(
'model' => $model,
'name' => 'sample',
'attribute' => 'sample',
'accept' => 'jpeg|jpg|gif|png',
'duplicate' => 'Duplicate file!',
'denied' => 'Invalid file type',
'remove' => '[x]',
'max' => 20,
));
This is the controller's code the(the function that dealing with the part):
public function actionCreate($project_id) {
$model = new Bid();
$project = $this->loadModel('Project', $project_id);
if (count($project->bids) == 5) {
Yii::app()->user->setFlash('warning', Yii::t('bids', 'This project has already reached its maximum number of bids, so you cannot post a new bid.'));
$this->redirect(array('project/view', 'id' => $project_id));
}
if (!empty($project->bid)) {
Yii::app()->user->setFlash('warning', Yii::t('bids', 'This project has a selected bid already, so you cannot post a new bid.'));
$this->redirect(array('project/view', 'id' => $project_id));
}
if ($project->closed) {
Yii::app()->user->setFlash('warning', Yii::t('bids', 'You cannot add bids as this project has been closed.'));
$this->redirect(array('project/view', 'id' => $project_id));
}
$model->project = $project;
if (isset($_POST['Bid'])) {
$model->attributes = $_POST['Bid'];
$photos = CUploadedFile::getInstancesByName('sample');
if (isset($photos) && count($photos) > 0) {
foreach ($photos as $image => $pic) {
$pic->name;
if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$pic->name)) {
// add it to the main model now
$img_add = new Bid();
$img_add->filename = $pic->name;
$img_add->save();
}
else {
}
}
}
$model->project_id = $project->id;
$model->freelancer_id = $this->currentUser->id;
if ($model->save()) {
$this->redirect(array('project/view', 'id' => $project->id, '#' => 'bidslist'));
}
}
$this->render('create', array(
'model' => $model,
));
}
Thanks in Advance.
Please let me know if anyone needs anything else for better understanding.
If i underssot you correctly when you saving the model
$img_add = new Bid();
$img_add->sample = $pic->name;
$img_add->save();
I am trying to add an additional image upload field to a gallery extension. The code for the extension controller is below. I've added an extra column to the database called galpic_popup_image with the same values as the existing galpic_image column.
I've managed to get the upload working, so images are saved on the server, however it isn't saving the filename in the database and therefore I can't call it on the frontend.
class ParadoxLabs_Gallery_Adminhtml_GalleryController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->_setActiveMenu('cms/gallery');
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Gallery'), Mage::helper('adminhtml')->__('Gallery'));
$this->renderLayout();
}
public function editAction()
{
$this->loadLayout();
$this->_setActiveMenu('cms/gallery');
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Gallery'), Mage::helper('adminhtml')->__('Gallery'));
$this->_addContent($this->getLayout()->createBlock('gallery/adminhtml_gallery_edit'));
$this->renderLayout();
}
public function newAction()
{
$this->editAction();
}
public function saveAction()
{
if ( $this->getRequest()->getPost() ) {
// Image uploading code modified from https://magento2.atlassian.net/wiki/spaces/m1wiki/pages/14024884/How+to+create+an+image+or+video+uploader+for+the+Magento+Admin+Panel
if(isset($_FILES['image']['name']) && (file_exists($_FILES['image']['tmp_name'])))
{
try{
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS . 'p_gallery' . DS ;
$uploader->save($path, $_FILES['image']['name']);
$data['image'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'p_gallery/'. $_FILES['image']['name'];
}catch(Exception $e){}
}
else
{
if(isset($data['fileinputname']['delete']) && $data['fileinputname']['delete'] == 1){
$data['image_main'] = '';
}
else{
unset($data['image']);
}
}
if(isset($_FILES['popup_image']['name']) && (file_exists($_FILES['popup_image']['tmp_name'])))
{
try{
$uploader = new Varien_File_Uploader('popup_image');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS . 'p_gallery' . DS ;
$uploader->save($path, $_FILES['popup_image']['name']);
$popupdata['popup_image'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'p_gallery/'. $_FILES['popup_image']['name'];
}catch(Exception $e){}
}
else
{
if(isset($popupdata['fileinputname']['delete']) && $popupdata['fileinputname']['delete'] == 1){
$popupdata['popup_image_main'] = '';
}
else{
unset($popupdata['popup_image']);
}
}
try {
if( intval($this->getRequest()->getParam('id')) == 0 ) { // New
$model = Mage::getModel('gallery/gallery')
->setGalpicId ( $this->getRequest()->getParam('id') )
->setGalpicStore( $this->getRequest()->getParam('store') )
->setGalpicDate ( date('Y-m-d', time()) )
->setGalpicName ( $this->getRequest()->getParam('name') )
->setGalpicImage( $data['image'] )
->setGalpicPopupImage( $popupdata['popup_image'] )
->save();
}
else { // Edit
$model = Mage::getModel('gallery/gallery')
->setGalpicId ( $this->getRequest()->getParam('id') )
->setGalpicStore( $this->getRequest()->getParam('store') )
->setGalpicName ( $this->getRequest()->getParam('name') )
->setGalpicImage( $data['image'] )
->setGalpicPopupImage( $popupdata['popup_image'] )
->save();
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Galpic was successfully saved'));
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
$this->_redirect('*/*/');
}
public function deleteAction()
{
if( $this->getRequest()->getParam('id') > 0 ) {
try {
$model = Mage::getModel('gallery/gallery');
$model->setGalpicId($this->getRequest()->getParam('id'))
->delete();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Galpic was successfully deleted'));
$this->_redirect('*/*/');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
}
}
$this->_redirect('*/*/');
}
protected function _isAllowed()
{
return Mage::getSingleton('admin/session')->isAllowed('cms/gallery');
}
}
And here is the form used to capture the data:
class ParadoxLabs_Gallery_Block_Adminhtml_Gallery_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'enctype' => 'multipart/form-data',
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
$fieldset = $form->addFieldset('gallery_form', array(
'legend' => Mage::helper('gallery')->__('Galpic'),
'class' => 'fieldset-wide'
)
);
$fieldset->addField('galpic_name', 'text', array(
'name' => 'name',
'label' => Mage::helper('gallery')->__('Name'),
'class' => 'required-entry',
'required' => true,
));
$fieldset->addField('galpic_image', 'image', array(
'name' => 'image',
'label' => Mage::helper('gallery')->__('Image'),
'class' => 'required-entry',
'required' => true,
));
$fieldset->addField('galpic_popup_image', 'image', array(
'name' => 'popup_image',
'label' => Mage::helper('gallery')->__('Popup Image'),
'class' => 'required-entry',
'required' => true,
));
$fieldset->addField('galpic_store', 'select', array(
'name' => 'store',
'label' => Mage::helper('core')->__('Store View'),
'title' => Mage::helper('core')->__('Store View'),
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
));
if (Mage::registry('gallery')) {
$form->setValues(Mage::registry('gallery')->getData());
}
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
Ok, I fixed it!
It was suggested to make sure the columns were in the same order as the controller saves the items so I did that. It didn't seem to have an effect (but it may have done).
I changed the second image upload code to the following (basically removed 'popup' from $popupdata as Kiatng suggested) above:
if(isset($_FILES['popup_image']['name']) && (file_exists($_FILES['popup_image']['tmp_name'])))
{
try{
$uploader = new Varien_File_Uploader('popup_image');
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media') . DS . 'p_gallery' . DS ;
$uploader->save($path, $_FILES['popup_image']['name']);
$data['popup_image'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'p_gallery/'. $_FILES['popup_image']['name'];
}catch(Exception $e){}
}
else
{
if(isset($data['fileinputname']['delete']) && $data['fileinputname']['delete'] == 1){
$data['image_main'] = '';
}
else{
unset($data['popup_image']);
}
}