Search
 
SCRIPT & CODE EXAMPLE
 

PHP

image upload in cake 2

   public function add() {
            if ($this->request->is('post')) {
                $this->Product->create();
                if ($this->Product->save($this->request->data)) {
                    $this->Session->setFlash(__('The product has been saved.'));
                    return $this->redirect(array('action' => 'index'));
                } else {
                    $this->Session->setFlash(__('The product could not be saved. Please, try again.'));
                }
                if(!empty($this->data))
                {
                    //Check if image has been uploaded
                    if(!empty($this->data['products']['upload']['name']))
                    {
                        $file = $this->data['products']['upload']; //put the data into a var for easy use

                        $ext = substr(strtolower(strrchr($file['name'], '.')), 1); //get the extension
                        $arr_ext = array('jpg', 'jpeg', 'gif'); //set allowed extensions

                        //only process if the extension is valid
                        if(in_array($ext, $arr_ext))
                        {
                            //do the actual uploading of the file. First arg is the tmp name, second arg is
                            //where we are putting it
                            move_uploaded_file($file['tmp_name'], WWW_ROOT . 'CakePHP/app/webroot/img/' . $file['name']);

                            //prepare the filename for database entry
                            $this->data['products']['product_image'] = $file['name'];
                        }
                    }

                    //now do the save
                    $this->products->save($this->data) ;
                }
            }

        }
Comment

image upload in cake 2

public function add() {
    if ($this->request->is('post')) {
        $this->Category->create();
        //Check if image has been uploaded
        if (!empty($this->request->data['Category']['upload']['name'])) {
            $file = $this->request->data['Category']['upload'];

            $ext = substr(strtolower(strrchr($file['name'], '.')), 1);
            $arr_ext = array('jpg', 'jpeg', 'gif','png');

            if (in_array($ext, $arr_ext)) {
                move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/webimages/categories/' . $file['name']);
                //prepare the filename for database entry
                $this->request->data['Category']['image'] = $file['name'];
            }
        }

        if ($this->Category->save($this->request->data)) {
            $this->Session->setFlash(__('The category has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The category could not be saved. Please, try again.'));
        }
    }
    $parentCategories = $this->Category->ParentCategory->find('list');
    $categoriesStatus = $this->Category->getCategoriesStatus();//model's method to get list of status
    $this->set(compact('parentCategories', 'categoriesStatus'));
}
Comment

PREVIOUS NEXT
Code Example
Php :: MethodNotAllowedHttpException 
Php :: wordpress profile queries 
Php :: Determine the percentage of the file uploaded to the server using php 
Php :: Debloat Wordpress 
Php :: Comment ajouter nofollow à un lien spécifique ou à tous les liens WordPress dans the_content 
Php :: how to disable auto prediction html input in laravel 
Php :: code snippet for header footer in wordpress 
Php :: small rce php 
Php :: auto complete order paid2 
Php :: WordPress Creating “startupl” folder and Wrtting to .htaccess 
Php :: php artisan spark not working in codeigniter 
Php :: ErrorException Undefined index(laravel 7 array helpers) 
Php :: php xpath get all tags under a tag 
Php :: laravel artisan command run in route 
Php :: laravel length validation 
Php :: automatically create html page using php and mysql 
Php :: check website ssl certificate using php openssl_x509_parse 
Php :: magento 2 block called as child pass product variable 
Php :: List all controllers in codeigniter HMVC structure 
Php :: moodle admin cli 
Php :: registration welcome email laravel 
Php :: laravel pdf generator 
Php :: swift mailer 530 Must issue a STARTTLS command first. 
Php :: laravel model bind with route in model 
Php :: find string lenght in php 
Php :: php abstract class static method 
Php :: unless blade laravel 
Php :: php mask credit card number 
Java :: how to print hello world in java 
Java :: How do you nuke japan 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =