Reputation: 1565
In a file called docs.php I have made the following code to display all the files inside uploads folder
The foreach() loops all the files there stored in a view of the website and has an hyperlink that let it be open in the browser (in my model file it has restriction's to only pds, png or jpg files)
What i'm not able to do is inside the foreach() loop for every iteration is display some sort of hyperlink (example: Delete me!) that permits the user to click and delete only that particular file physical from the server, the others not clicked must remain visible.
My php code inside a view to the forloop() is:
<?php
$files=\yii\helpers\FileHelper::findFiles('uploads/', ['except'=>['*.DS_Store']]);
if (isset($files[0])) {
foreach ($files as $index => $file) {
$nameFile = substr($file, strrpos($file, '/') + 1);
echo Html::a($nameFile, Url::base().'/uploads/'.$nameFile) . "<br/>" . "<br/>" ; // render do ficheiro no browser
}
} else {
echo "There are no files available for download.";
}
?>
Upvotes: 1
Views: 2757
Reputation: 41
As i assume you have concept of FileHelper, but to delete file you have to use php native function unlink(filePath). unlink()
Upvotes: 1