good day
I need help to create a button that allows me to delete files uploaded to the uploads folders from yii2
thanks
good day
I need help to create a button that allows me to delete files uploaded to the uploads folders from yii2
thanks
good day
For those who require this type of information to implement buttons I leave the code that worked for me to perform this function of the app
<div class="col-lg-10 col-md-10">
<?php
if (!$model->isNewRecord) {
if (!file_exists(Yii::$app->basePath . '/images/qhse/accidentes/' . $model->id)) {
mkdir(Yii::$app->basePath . '/images/qhse/accidentes/' . $model->id, 0777, true);
}
$listar = null;
$directorio = scandir(Yii::$app->basePath . '/images/qhse/accidentes/' . $model->id . '/');
if (count($directorio) <= 2) {
$listar = "El Accidente no contiene Arhcivos Adjuntos";
}
$directorio = opendir(Yii::$app->basePath . '/images/qhse/accidentes/' . $model->id . '/');
while ($documento = readdir($directorio)) {
if ($documento != '.' && $documento != '..') {
if (is_dir(Yii::$app->basePath . '/images/qhse/accidentes/' . $model->id . '/')) {
$listar .= $a = '<li><i class="fa fa-file"></i>' . ' ' . ' ' .
Html::a($documento, Yii::$app->homeUrl . 'images/qhse/accidentes/' . $model->id . '/' . $documento) .
' ' .
' ' .
' ' .
' ' .
' ' .
' ' .
Html::a("<i class='fa fa-trash'></i>", ['filedelete', 'archivo' => Yii::$app->basePath . '/images/qhse/accidentes/' .
$model->id . '/' . $documento], ['class' => 'btn btn-danger',
'data' => [
'confirm' => 'Estás seguro de que quieres eliminar ' . $documento . '?'
]])
. '</li>';
} else {
$listar .= $a = '<li><i class="fa fa-download"></i>' . ' ' . ' ' .
Html::a($documento, Yii::$app->homeUrl . 'images/qhse/accidentes/' . $model->id . '/' . $documento) .
' ' .
' ' .
' ' .
' ' .
' ' .
' ' .
Html::a("<i class='fa fa-trash'></i>", ['filedelete', 'archivo' => Yii::$app->basePath . '/images/qhse/accidentes/' .
$model->id . '/' . $documento], ['class' => 'btn btn-danger',
'data' => [
'confirm' => 'Estás seguro de que quieres eliminar ' . $documento . '?'
]])
. '</li>';
}
}
}
?>
<ul>
<p><span style="color: #3366ff;"><strong>Documentos Cargados</strong></span></p>
<p><span style="color: #3366ff;"><strong><?= $listar ?></strong></span></p>
</ul>
<?php
}
?>