Answer the question
In order to leave comments, you need to log in
How to remove an image using ajax request?
There is a field for uploading files in the view (multiple upload)
<?= $form->field($images, 'imagesFiles[]')->fileInput(['multiple' => true, 'accept' => 'image/*','id'=>'gallery-photo-add'])->label(false) ?>
$images->imagesFiles = UploadedFile::getInstances($images, 'imagesFiles');
Answer the question
In order to leave comments, you need to log in
so that they can be removedtheir whom? Files or previews, since js usually creates previews before uploading to the server. For
public function actionDeleteMyImage($id){
if($model = MyModel::findOne($id)){
$path = '/путь/к/папке/с/картинками/от/корня/сервера/'.$model->image_name;
if(file_exists($path)){
unlink($path);
return true;
}
}
return false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question