Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Upload Image in cake php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 291
    Comment on it

    Image uploading in cake php is a common task for building application and making it more interesting by using many images to the screen, so here is some line of code used for uploading an image and resize it according to user's need by using Qimage component and then save it to the database in the encrypted form by using 'enctype' method in html from. A user can mention the name, type and path of the file in the form of array this file will be  uploaded and then save to the database if image save successfully user will get flash message on screen.

    HTML Source Code:

    
    <div class="upload clearfix">
     <?php echo  $this->Form->input('user_image.',array('type'=>'file', 'multiple'=>true,'onchange'=>"readURL(this)",));?>
    
      <img id="image_upload_preview" src="<?php echo $this->webroot;?>images/profile.png" alt="your 
    image" class='image_upload_preview'/>
     </div>

    Controller Code:

    if ($this->request->data['Project']['user_image']!='' && is_array($this->request->data['Project'
    ['user_image'])) 
                {
                    $user_image=null;
                    foreach($this->request->data['Project']['user_image'] as $key => $profile)
                     {
                    $imgData = array();
                    $imgData['file'] = $profile;
                    $imgData['name']=$profile['name'];
                    $imgData['path'] = WWW_ROOT . '' . 'images/uploads/';
                    unset($this->request->data['Project']['user_image']);
                    $user_image =$this->Qimage->copy($imgData).",".$user_image ;
                    //$image_name=$image_name,
                    }
                }
                    else{
                    $user_image = "";
                    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: