I am storing some files in public folder, programmatically I want to delete those files through the provided path. I tried using below code, but not worked.
function delete_public_files($arg1, $arg2){
$uri = 'public://';
$path= file_create_url($uri);
$fullpath = $path.$arg1.'/'.$arg2;
//file_unmanaged_delete($fullpath);
$fid = db_query("SELECT fid FROM {file_managed} WHERE uri = :path", array(':path' => $fullpath))->fetchField();
if ($fid) {
$file = file_load($fid);
file_delete($file);
}
else {
file_unmanaged_delete($fullpath);
}
}
These files are not recorded in the file_managed table and file_usage table also. So how can I delete these files. If I pass the path to file_delete($fullpath);
It will says error that first argument should be object. So how can I achieve all these things. Thanks for any appreciation.