ian using image upload using ajax ,tryed efileupload extenstion that is not working ,anyone give me idea how to solve
ian using image upload using ajax ,tryed efileupload extenstion that is not working ,anyone give me idea how to solve
Hi murugan,
Please post your error. Without error how can we provide solution for you
I need a some help of ajax onclick button based send file input to controller anybody help ,tryed some extension its not working ,anyone help
This is my solution that is working correctly, i hope this can help you.
Note: this working to saving images in local and route in database.
Code create image (scenario ‘insert’)
$model = new YourModel('insert');
$this->performAjaxValidation(array($model), 'your-form');
if (isset($_POST['YourModel'])) {
$model->setAttributes($_POST['YourModel']);
$model->image=CUploadedFile::getInstance($model,'image');
if($model->validate()){
if($model->save(false)){
$model->image->saveAs('images/yourDirectory/'.$model->image);
Code update image (scenario ‘update’)
$model = $this->loadModel($id, 'YourModel');
$model->setScenario('update');
$this->performAjaxValidation(array($model), 'your-form');
if (isset($_POST['YourModel'])) {
$model->setAttributes($_POST['Route']);
$uploadedFile=CUploadedFile::getInstance($model,'image');
if($model->validate()){
if($model->save(false)){
if(!empty($uploadedFile))
$model->image->saveAs('images/yourDirectory/'.$model->image);
i know this way how to upload ajax based ,any one will give ideas