I have trouble deleting Files on Drupal 8. How can you delete any kind of Files for example in my case a picture file (jpg, png etc...). In Drupal 7, you have the option on the right side to Delete the file , but Drupal 8 does not have that option ...only for published pages. Is ther any chance to delete files just for any reason if you do not want them any more, without any complicated task ?
P.S: I am a beginner Drupal user !Thanks
3 Answers3
In Drupal 8 there is no need of that option, since there is cron which will be running automatically to delete unused images.
3 Comments
There is no native way from the Drupal 8 admin interface to delete images from the file uploader in Drupal. However you can install the Drupal 8 IMCE module which will give you access to the file system when you are login. That way you can remove files.
Here is a link to the module.https://www.drupal.org/project/imce
Comments
You can erase images from a custom module. This is only tested in Drupal 8.9. First let me explain the image process so you can better understand if this solution is the right fit for you. An fid is stored in the column of your custom table you use to reference your image. It is the primary key in a table called file_managed that stores the image information. The image is stored in the "web/sites/default/files" folder. This might be different depending on your Drupal installation. table_usage stores the usages of the image on the site. When you erase an image you need to erase the row with your images fid from all three tables file_managed, file_usage and your table. Then of course unlink your image.
/** * Removes an image.** @param $fid* @return boolean*/public function removeImage($fid) { if ( empty($fid) || !preg_match('/^[0-9]+$/', trim($fid)) ) return FALSE; // Im assigning the $this->database property an instance of Connection $result = $this->database->query("SELECT uri FROM {file_managed} where fid=:fid", [':fid' => $fid])->fetchCol(); $absolute_path = \Drupal::service('file_system')->realpath($result[0]); if(isset($absolute_path)) unlink($absolute_path); //var_dump($absolute_path); exit(); $this->database->delete('file_managed') ->condition('fid', $fid) ->execute(); $this->database->delete('file_usage') ->condition('fid', $fid) ->execute(); return true;}Comments
Explore related questions
See similar questions with these tags.




