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)