i try to updating three tables with one button execution, but why just t_user that changed? t_publisher and t_label didnt change and no error warning..
function update($id_user=null){
if (($this->input->post('submit') == 'Update')){
$user=$this->input->post('username');
$pass=$this->input->post('userpassword');
$ussta=$this->input->post('userstatus');
$usty=$this->input->post('usertype');
$id_label = $this->db->query("select ID_LABEL from t_label where LABEL = '$name->USER_NAME'")->row();
$id_publisher = $this->db->query("select ID_PUBLISHER from t_publisher where PUBLISHER = '$name->USER_NAME'")->row();
$data = array(
'USER_NAME' => $user,
'USER_PASS' => $pass,
'USER_STATUS' => $ussta,
'USER_TYPE' => $usty
);
$data2 = array(
'LABEL' => $user,
);
$data3 = array(
'PUBLISHER' => $user,
);
$this->db->where('USER_ID', $this->input->post('id'));
$this->db->update('t_user', $data);
$this->db->where('ID_LABEL', $this->input->post('$id_label'));
$this->db->update('t_label', $data2);
$this->db->where('ID_PUBLISHER', $this->input->post('$id_publisher'));
$this->db->update('t_publisher', $data3);
redirect("registrasi/reg");
}
$var['data'] = $this->db->query("select * from t_user where USER_ID= '$id_user'")->row_array();
$this->load->view('update', $var);
}
please help :)
Try
function update( $id_user = NULL ){
if ( ( $this->input->post( 'submit' ) === 'Update' ) ) {
$user = $this->input->post( 'username' );
$pass = $this->input->post( 'userpassword' );
$ussta = $this->input->post( 'userstatus' );
$usty = $this->input->post( 'usertype' );
$sql = "SELECT ID_LABEL FROM t_label WHERE LABEL = ?";
$id_label = $this->db->query( $sql, array( $name->USER_NAME ) )->row();
$sql = "SELECT ID_PUBLISHER FROM t_publisher WHERE PUBLISHER = ?";
$id_publisher = $this->db->query( $sql, array( $name->USER_NAME ) )->row();
$data = array(
'USER_NAME' => $user,
'USER_PASS' => $pass,
'USER_STATUS' => $ussta,
'USER_TYPE' => $usty
);
$data2 = array(
'LABEL' => $user,
);
$data3 = array(
'PUBLISHER' => $user,
);
$this->db->where('USER_ID', $this->input->post('id'));
$this->db->update('t_user', $data);
$this->db->where('ID_LABEL', $id_label);
$this->db->update('t_label', $data2);
$this->db->where('ID_PUBLISHER', $id_publisher);
$this->db->update('t_publisher', $data3);
redirect("registrasi/reg");
}
$var['data'] = $this->db->query( "SELECT * FROM t_user WHERE USER_ID= '$id_user'")->row_array();
$this->load->view('update', $var);
}
I'm a bit confused. Is it a model file? If it's so, why there is a redirect command? And also why there is a $this->load->view()? And once more, where $name came from? You assign $id_user as default parameter, where do you use it in this file?
Related
I did count active in 7 days topics of my Wordpress page. But It counts only Active (replied) topics not actual replies- I need more dynamic number to lure people using forum.
function count_new_forum_posts() {
$today = date("Y-m-d");
$date2 = date("Y-m-d", strtotime($today . "-7 Day"));
$args = array(
'post_type' => 'topic',
'meta_query' => array(
array(
'key' => '_bbp_last_active_time',
'value' => $date2,
'type' => 'DATE',
'compare' => '>='
),
)
);
$posts_query = new WP_Query($args);
$the_count = $posts_query->post_count;
return $the_count;
}
add_filter('wp_nav_menu_items', 'new_forums_notice_to_menu', 10, 2);
function new_forums_notice_to_menu($items, $args) {
if(count_new_forum_posts() > 0){
if( $args->theme_location == 'primary' )
$items .= '<li><font color="red">Šios savaitės naujos žinutės forume: <span>'.count_new_forum_posts().'</span></font></li>';
return $items;
}else{
if( $args->theme_location == 'primary' )
$items .= '<li><font color="gray">Šią savaitę forume dar niekas nepasisakė</span></font></li>';
return $items;
}
}
When i try to change post_type to 'reply' or 'replies' It counts to 0.
where I use Helperform. I want to make some fields translatable. I added the following form:
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Diplom hinzufügen'),
'icon' => 'icon-question'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'lang' => true,
),
),
'submit' => array('title' => $this->l('Save'))
)
);
$helper = new HelperForm();
$helper->submit_action = 'saveDiplom';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => array(
'name' => '',
),
);
return $helper->generateForm(array($fields_form));
I don't see the "name" field in the backoffice. What is wrong? If I delete 'lang' => true it shows up.
Is there any other setting needed (like in the constructor)?
This is a standard HelperForm initialization:
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitNameOfModuleModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
. '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs, in your case you have passed the array directly */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
I guess you forgot the 'languages' in the tpl_vars array and the id_language too.
Maybe this link should be helpful.
it's my first post so sorry in case i will do some mistakes. I am getting mad from this morning because of this function:
public function viewpdf0($agent_id = null, $month = null, $year = null){
if(!empty($agent_id)){
$this->create_remittance($agent_id, $month, $year);
$this->layout = '/pdf/default';
$this->render('/Pdf/remittance_0');
sleep(1);
$this->redirect('/files/remittances/STAT_'.str_pad($month, 2, '0', STR_PAD_LEFT).'_'.str_pad($year, 0, '0', STR_PAD_LEFT).'_'.$agent['Registry']['hash'].'_TEMP.pdf');
}
}
The problem started when i decided to take off the calculations from the viewpdf0 function and putting it into the create_remittance function.
When i click on the button "Print Pdf" i get the following error:
Missind Controller for files. This mean that the Cakephp is processing the redirect thinking to find a controller called files!!!!
It's very strange, because if i put again the calculation functions directly inside the viewpdf0 function it works.
Below part of the create_remittance function:
public function create_remittance($agent_id = null, $month = null, $year = null) {
$agent = $this->Registry->findById($agent_id);
$this->set('agent', $agent);
$conditions = array();
array_push($conditions , array('Dossier.active' => '1'));
array_push($conditions , array('Edossier.active' => '1'));
array_push($conditions , array('OR' =>
array(
array(
'Dossier.item_parent_id' => '43'
),
array(
'Dossier.item_parent_id' => '44'
)
)
));
//20:POLIZZA EMESSA - 17:PERFEZIONATA - 14:ATTESA DOC. ORIGINALI - 18:CARICATA
array_push($conditions , array('Dossier.state_id' => array(20,17,14,18)));
array_push($conditions , array('EXTRACT(MONTH FROM "Edossier"."date_emissione") =' => $month));
array_push($conditions , array('EXTRACT(YEAR FROM "Edossier"."date_emissione") =' => $year));
array_push($conditions , array('Dossier.agent_id' => $agent_id));
$query = array(
'fields' => array( 'DISTINCT Dossier.id',
'Agent.surname'
),
'joins' => array(
array('table' => 'items',
'alias' => 'Item',
'type' => 'LEFT',
'conditions' => array('Dossier.item_id = Item.id'),
),
array('table' => 'edossiers',
'alias' => 'Edossier',
'type' => 'LEFT',
'conditions' => array('Edossier.dossier_id = Dossier.id'),
),
array('table' => 'registries',
'alias' => 'Registry',
'type' => 'LEFT',
'conditions' => array('Dossier.registry_id = Registry.id'),
),
array('table' => 'registries',
'alias' => 'Agency',
'type' => 'LEFT',
'conditions' => array('Dossier.insurance_agency_id = Agency.id'),
),
array('table' => 'registries',
'alias' => 'Company',
'type' => 'LEFT',
'conditions' => array('Dossier.insurance_company_id = Company.id'),
),
array('table' => 'states',
'alias' => 'State',
'type' => 'LEFT',
'conditions' => array('Dossier.state_id = State.id'),
),
array('table' => 'categories',
'alias' => 'Product',
'type' => 'LEFT',
'conditions' => array('Dossier.item_parent_id = Product.id'),
),
array('table' => 'registries',
'alias' => 'Agent',
'type' => 'LEFT',
'conditions' => array('Dossier.agent_id = Agent.id'),
),
array('table' => 'states',
'alias' => 'RenewedState',
'type' => 'LEFT',
'conditions' => array('Dossier.renewed_state_id = RenewedState.id'),
),
),
'conditions' => $conditions,
'recursive' => -1
);
$dossiers = $this->Dossier->find('all', $query);
$this->set('dossiers', $dossiers);
$debug_dossier = '';
$edossiers = array();
$edossiers3 = array();
$dossier_ids = array();
$total_gross = 0;
$total_taxes = 0;
$total_equity = 0;
$total_fees_gross = 0;
$total_bill_tax = 0;
foreach($dossiers as $dossier){
// Query su type=1 ossia rata di pagamento
$edossier_all = $this->Edossier->find('all', array(
'conditions' => array(
'Edossier.active' => '1',
'Edossier.dossier_id' => $dossier['Dossier']['id'],
'Edossier.type' => '1',
'Edossier.month' => $month,
'Edossier.year' => $year
),
'order' => array(
'Edossier.id ASC'
)
));
// Query su type=2 ossia storno di pagamento
$edossier3_all = $this->Edossier->find('all', array(
'conditions' => array(
'Edossier.active' => '1',
'Edossier.dossier_id' => $dossier['Dossier']['id'],
'Edossier.type' => '2',
'Edossier.month' => $month,
'Edossier.year' => $year
),
'order' => array(
'Edossier.id ASC'
)
));
foreach($edossier_all as $edossier){
if(!empty($edossier)){
$item = $this->Item->findById($edossier['Dossier']['item_id']);
$agent_name = $this->Registry->findById($edossier['Dossier']['agent_id']);
$state = $this->State->findById($edossier['Dossier']['state_id']);
$registry = $this->Registry->findById($edossier['Dossier']['registry_id']);
$cashflow = $this->Cashflow->findByHash($edossier['Edossier']['cashflow_hash']);
$edossier['Agent'] = $agent_name;
$edossier['Item'] = $item;
$edossier['State'] = $state;
$edossier['Registry'] = $registry;
$edossier['Cashflow'] = $cashflow;
array_push($edossiers, $edossier);
$total_gross = $total_gross + $edossier['Edossier']['gross'];
$total_taxes = $total_taxes + $edossier['Edossier']['taxes'];
$total_equity = $total_equity + $edossier['Edossier']['equity'];
$total_fees_gross = $total_fees_gross + $edossier['Edossier']['fees_gross'];
$total_bill_tax = $total_bill_tax + $edossier['Edossier']['bill_tax'];
}
}
foreach($edossier3_all as $edossier3){
if(!empty($edossier3)){
$total_gross = $total_gross - $edossier3['Edossier']['value'];
$total_taxes = $total_taxes - $edossier3['Edossier']['taxes'];
$total_equity = $total_equity - $edossier3['Edossier']['equity'];
$total_fees_gross = $total_fees_gross - $edossier3['Edossier']['fees_gross'];
$total_bill_tax = $total_bill_tax - $edossier3['Edossier']['bill_tax'];
array_push($edossiers3, $edossier3);
}
}
array_push($dossier_ids, $dossier['Dossier']['id']);
$debug_dossier .= $dossier['Dossier']['id'] .',';
}
//Trovo tutte le rate pagate per conteggiare il totale pagato, nelle successive righe
$edossiers2 = $this->Edossier->find('all', array(
'conditions' => array(
'Edossier.active' => '1',
'Edossier.dossier_id' => $dossier_ids,
'Edossier.payed' => '1',
'Edossier.month' => $month,
'Edossier.year' => $year
)
));
$edossier_ids = array();
foreach($edossiers as $edossier){
array_push($edossier_ids, $edossier['Edossier']['id']);
}
$total_payed = 0;
foreach($edossiers2 as $edossier2){
//$cashflow = $this->Cashflow->findByHash($edossier2['Edossier']['cashflow_hash']);
//$total_payed = $total_payed + $cashflow['Cashflow']['qty'];
$cashflows = $this->Cashflow->find('all', array(
'conditions' => array(
'Cashflow.edossier_id' => $edossier2['Edossier']['id'],
'Cashflow.active' => '1'
)
));
foreach ($cashflows as $cashflow) {
$total_payed = $total_payed + $cashflow['Cashflow']['qty'];
}
}
$this->set('total_gross', $total_gross);
$this->set('total_taxes', $total_taxes);
$this->set('total_equity', $total_equity);
$this->set('total_fees_gross', $total_fees_gross);
$this->set('total_bill_tax', $total_bill_tax);
$this->set('total_payed', $total_payed);
$this->set('edossiers3', $edossiers3);
$this->set('edossiers2', $edossiers2);
$this->set('edossiers', $edossiers);
$this->set('agent', $agent);
$this->set('dossier_ids', $dossier_ids);
$this->set('edossier_ids', $edossier_ids);
$this->set('month', $month);
$this->set('year', $year);
$this->set('debug_dossier', $debug_dossier);
}
I solved the issue just inserting an array return in the function create_remittance and in the function viewpdf0 i fixed in this way:
$remittance = $this->create_remittance($agent_id, $month, $year);
Thank you.
I need to integrate Easypay.pt with opengateway so if any one know somehting about this i would like to know if some one can help for this i will appreciate thanks
function Settings () {
$settings = array();
$settings['name'] = 'Easypay';
$settings['class_name'] = 'easypay';
$settings['external'] = FALSE;
$settings['no_credit_card'] = FALSE;
$settings['description'] =
'Easypay is a portuguese company that offers a universal payment
platform and is certified by SIBS, Unicre, Visa and MasterCard. Our
primary mission is helping the market to shorten the payment
processing time and offer greater flexibility and convenience in
payment.';
$settings['is_preferred'] = 1;
$settings['setup_fee'] = '$0.00';
$settings['monthly_fee'] = '$30.00';
$settings['transaction_fee'] = '2.5% + $0.30';
$settings['purchase_link'] = 'https://www.easypay.pt/_s/api_easypay_01BG.php';
$settings['allows_updates'] = 0;
$settings['url_live'] = 'https://www.easypay.pt/_s/api_easypay_01BG.php ';
$settings['url_test'] = 'http://test.easypay.pt/_s/api_easypay_01BG.php';
$settings['allows_refunds'] = 1;
$settings['requires_customer_information'] = 1;
$settings['requires_customer_ip'] = 1;
$settings['required_fields'] = array(
'enabled',
'mode',
'ep_cin',
'ep_user',
'ep_ref_type',
'ep_entity',
't_key',
'ep_language',
'ep_country'
);
$settings['field_details'] = array(
'enabled' => array(
'text' => 'Enable this gateway?',
'type' => 'radio',
'options' => array(
'1' => 'Enabled',
'0' => 'Disabled'
)
),
'mode' => array(
'text' => 'Mode',
'type' => 'select',
'options' => array(
'live' => 'Live Mode',
'test' => 'Test Mode'
)
),
'ep_cin' => array(
'text' => 'Client Identification Number',
'type' => 'text'
),
'ep_user' => array(
'text' => 'Username',
'type' => 'text'
),
'ep_ref_type' => array(
'text' => 'Type of Identifier',
'type' => 'select',
'options' => array(
'auto' => 'Auto',
)
),
'ep_type' => array(
'text' => 'Type',
'type' => 'select',
'options' => array(
'boleto' => 'Boleto',
)
),
'ep_entity' => array(
'text' => 'Entity in use by Your Account.',
'type' => 'text',
),
't_key' => array(
'text' => 'Transaction key',
'type' => 'text',
),
'ep_language' => array(
'text' => 'Language',
'type' => 'select',
'options' => array(
'PT' => 'PT',
)
),
'ep_country' => array(
'text' => 'Currency',
'type' => 'select',
'options' => array(
'PT' => 'PT',
)
)
);
return $settings;
}
function TestConnection($client_id, $gateway) {
// Get the proper URL
switch($gateway['mode']) {
case 'live':
$post_url = $gateway['url_live'];
break;
case 'test':
$post_url = $gateway['url_test'];
break;
}
$post = array();
$post['ep_cin'] = $gateway['ep_cin'];
$post['ep_user'] = $gateway['ep_user'];
$post['ep_entity'] = $gateway['ep_entity'];
$post['ep_ref_type'] = $gateway['ep_ref_type'];
$post['ep_type'] = 'boleto';
$post['t_value'] = '504.4';
$post['ep_country'] = $gateway['ep_country'];
$post['ep_language'] = $gateway['ep_language'];
$post['s_code'] = 'sssssssssssyour code ddddddd';
$post['t_key'] = $gateway['t_key'];;
$response = $this->Process($post_url, $post);
$status=$response->ep_status;
//$CI =& get_instance();
if($status != 'err1') {
return TRUE;
} else {
return FALSE;
}
}
//--------------------------------------------------------------------
function Process($url, $post, $order_id = FALSE) {
$response = simplexml_load_file(
$url . "ep_cin=" . $post['ep_cin'] . "&ep_user=" . $post['ep_user']
. "&ep_entity=" . $post['ep_entity'] . "&ep_ref_type=" . $post['ep_ref_type']
. "&ep_type=" . $post['ep_type'] . "&ep_country=" . $post['ep_country']
. "&ep_language='" . $post['ep_language'] . "'&s_code=" . $post['s_code']
. "&t_key=" . $post['t_key'] . "&t_value=" . $post['t_value']
);
return $response;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
private function response_to_array($string) {
$string = urldecode($string);
$pairs = explode('&', $string);
$values = array();
foreach($pairs as $pair) {
list($key, $value) = explode('=', $pair);
$values[$key] = $value;
}
return $values;
}
How can I rename the name of a file before to upload zf2 and Amazon S3?
This is my code:
$files = $request->getFiles();
$bucketname = 'mybucket';
$result = $aws->putObject(array(
'Bucket' => $bucketname,
'Key' => 'user/5/'.$files['image-file']['name'],
'Body' => EntityBody::factory(fopen($files['image-file']['tmp_name'], 'r')),
'ACL' => CannedAcl::PUBLIC_READ,
'ContentType' => 'image/jpeg'
));
I can not use the module https://github.com/aws/aws-sdk-php-zf2
This is a working example t upload the image in zf2,rename it and save to database
namespace Admin\Form;
use Zend\Form\Form;
class SubcategoryimageForm extends Form
{
public function __construct($name = null)
{
parent::__construct('Subcategoryimage');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/form-data');
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'subcategory_link_id',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'alt',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Alt Text',
),
));
$this->add(array(
'name' => 'fileupload',
'attributes' => array(
'type' => 'file',
),
'options' => array(
'label' => 'File Upload',
),
));
$this->add ( array (
'name' => 'detail',
'attributes' => array (
'type' => 'textarea'
),
'options' => array (
'label' => 'Detail'
)
) );
$this->add ( array (
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'active',
'tabindex' => 3,
'options' => array (
'label' => 'Active',
'use_hidden_element' => true,
'checked_value' => '1',
'unchecked_value' => '0'
)
) );
$this->add(array(
'type' => 'Zend\Form\Element\Radio',
'name' => 'location',
'options' => array(
'label' => 'Please choose one of the choices',
'value_options' => array(
'1' => 'flag',
'2' => 'landing',
'3' => 'home page',
),
),
'attributes' => array(
'value' => '1' //set checked to '1'
)
));
$this->add ( array (
'name' => 'submit',
'type' => 'Submit',
'tabindex' => 5,
'size' => 20,
'required' => false,
'attributes' => array (
'value' => 'Upload File',
'id' => 'submitbutton'
)
) );
}
}
In your controller
//inculde the imagine modules
use Zend\Validatior\File\Size;
use Imagine\Gd\Imagine;
use Imagine\Image\Box;
use Imagine\Image\Point;
public function imageAction()
{
$id = ( int ) $this->params ()->fromRoute ( 'id', 0 );
if (! $id) {
return $this->redirect ()->toRoute ( 'category' );
}
$form = new SubcategoryimageForm();
$form->get ( 'subcategory_link_id' )->setAttribute ( 'value', $id );
$request = $this->getRequest();
if ($request->isPost()) {
// Make certain to merge the files info!
$image = new Subcategoryimage();
$form->setInputFilter($image->getInputFilter());
$post = array_merge_recursive(
$request->getPost()->toArray(),
$request->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid()) {
$size = new \Zend\Validator\File\ImageSize(array(
'minWidth' => 30, 'minHeight' => 30,
'maxWidth' => 1024, 'maxHeight' => 920,
)); //minimum bytes filesize
$isImage = new \Zend\Validator\File\IsImage();
$mimeType = new \Zend\Validator\File\MimeType(array('image/gif', 'image/jpg','image/jpeg','image/png','enableHeaderCheck' => true));
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->setValidators(array($size), $post['fileupload']['name']);
$adapter->setValidators(array($isImage), $post['fileupload']['name']);
$adapter->setValidators(array($mimeType), $post['fileupload']['name']);
if (!$adapter->isValid()){
$dataError = $adapter->getMessages();
$error = array();
foreach($dataError as $key=>$row)
{
$error[] = $row;
}
$form->setMessages(array('fileupload'=>$error ));
$messages = $form->getMessages();
return $this->redirect ()->toRoute ( 'category' );
// print_r($messages);die('file errors');
} else {
//$adapter->setDestination(dirname(__DIR__).'imageurltosaveimage/');
$adapter->setDestination('imagepathtosave');
if ($adapter->receive($post['fileupload']['name'])) {
$image->exchangeArray($form->getData());
switch(strtolower($_FILES['fileupload']['type']))
{
case 'image/jpeg':
$filename = imagecreatefromjpeg('imagepath/'.$post['fileupload']['name']);
break;
case 'image/png':
$filename = imagecreatefrompng('imagepath/'.$post['fileupload']['name']);
break;
case 'image/gif':
$filename = imagecreatefromgif('imagepath/'.$post['fileupload']['name']);
break;
default:
exit('Unsupported type: '.$_FILES['fileupload']['type']);
}
ob_start();
imagejpeg($filename);
// large image
$large = base64_encode(ob_get_contents()); // returns output
$mainimgWidth = imagesx($filename);
$mainimgHeight = imagesy($filename);
$thumbWidth = intval($mainimgWidth / 4);
$thumbHeight = intval($mainimgHeight / 4);
$new = imagecreatetruecolor($thumbWidth, $thumbHeight);
$backgroundColor = imagecolorallocate($new, 255, 255, 255);
imagefill($new, 0, 0, $backgroundColor);
imagecopyresampled($new, $filename, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainimgWidth, $mainimgHeight);
/** Catch the imagedata */
ob_start();
imagejpeg($new);
$data = ob_get_clean();
// Destroy resources
imagedestroy($filename);
imagedestroy($new);
// Set new content-type and status code
$thumb = base64_encode($data);
// imagine library was intsalled by the composer in the test server by amarjit
ob_end_clean();
$imagine = new Imagine();
//rename files
$filedata = array(
'id' => $post ['id'],
'subcategory_link_id' => $post ['subcategory_link_id'],
'alt' => $post ['alt'],
'detail' => $post ['detail'],
'active' => $post ['active'],
'location' => $post ['location'],
'thumb' => $thumb,
'large' => $large,
'created' => date('Y-m-d H:i:s'),
'createdby' => 1,
);
$id = $this->getImageTable ()->save ( $filedata );
$imagine->open('ipathofimage/'.$post['fileupload']['name'])
->save('pathtosaveimages/newnameofimage-'.$id.'.jpg');
/**
* delete the origional uploaded file;
*/
unlink('pathtoimage/'.$post['fileupload']['name']);
return $this->redirect ()->toRoute ( 'category' );
}
}
}else{
$messages = $form->getMessages();
}
}
return array (
'id' => $id,
'form' => $form,
'entities' => $this->getImageTable ()->getImageContents($id),
);
}
To get the image from database
use below code in your action
public function getlandingimageAction()
{
$id = ( int ) $this->params ()->fromRoute ( 'id', 0 );
if (! $id) {
return $this->redirect ()->toRoute ( 'category' );
}
try {
$thumb = $this->getImageTable ()->getImage ( $id );
} catch ( \Exception $ex ) {
return $this->redirect ()->toRoute ( 'category', array (
'action' => 'index'
) );
}
$image = base64_decode($thumb);
/** check if the image is db */
if($image!=null)
{
$db_img = imagecreatefromstring($image);
Header("Content-type: image/jpeg");
imagejpeg($db_img);
}
else
{
/** check if the image is upload dir */
$url= "path/imagename".$id.'.jpg';
if(file_exists($url))
{
$db_img = imagecreatefromjpeg($url);
Header("Content-type: image/jpeg");
imagejpeg($db_img);
exit;
}
/** handle if the image does not exit */
/**
* This needs to be changed from t
*/
$imgurl= "paaathofimage/";
Header("Content-type: image/gif");
$i=imagecreatefromgif($imgurl."/images/noimg.gif");
imagegif($i);
}
exit;
}