Delete File programmatic... help needed

Permalink
heloo all,

A simply query. I am using concrete for a website which offer a download page which supplies files to download. For the admin part,I need build feature that admins can remove files from the list. I have created a checkbox list and I can bring the file ID in the posted area after Delete button submition. (pls see the attached image)

I have tried with this api function

$f->delete to delete the file, it gave me an error says below

Fatal error: Call to a member function delete() on a non-object in /srv/www/htdocs/cefil/blocks/list_files_from_set/templates/table_layout.php on line 16


here is the my code for posted files deletions

-------------------------------------------------------------


if(isset($_POST['delete'])) {
foreach ($_POST['file'] as $myFile) {
echo $myFile;
$f->delete($myFile);

}
}

-------------------------------------------------------------

$myFile is the file ID of which was posted by checkbox selection and submitted through Delete button. But I am not able to delete the files, pls pls help needed.

1 Attachment

jeevanism
 
jeevanism replied on at Permalink Reply
jeevanism
OK , its fixed now.

I missed a step here. the code must be like this

-------------------------------------------------
if(isset($_POST['delete'])) {
foreach ($_POST['file'] as $myFile) {
echo $myFile;

$f = File::getByID($myFile);
$f->delete();

}
}
-------------------------------------------------

I missed to add the line

$f = File::getByID($myFile);


thank you