Backend\Core\Engine\Model::deleteThumbnails PHP Метод

deleteThumbnails() публичный статический Метод

Delete thumbnails based on the folders in the path
public static deleteThumbnails ( string $path, string $thumbnail )
$path string The path wherein the thumbnail-folders exist.
$thumbnail string The filename to be deleted.
    public static function deleteThumbnails($path, $thumbnail)
    {
        // if there is no image provided we can't do anything
        if ($thumbnail == '') {
            return;
        }
        $finder = new Finder();
        $filesystem = new Filesystem();
        foreach ($finder->directories()->in($path) as $directory) {
            $fileName = $directory->getRealPath() . '/' . $thumbnail;
            if (is_file($fileName)) {
                $filesystem->remove($fileName);
            }
        }
    }

Usage Example

Пример #1
0
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendHotelsModel::exists('hotels_rooms', $this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // get data
         $this->record = (array) BackendHotelsModel::getRecord('hotels_rooms', $this->id);
         if ($this->record['image']) {
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/rooms/images';
             BackendModel::deleteThumbnails($imagePath, $this->record['image']);
         }
         // delete item
         BackendHotelsModel::deleteRecord('hotels_rooms', $this->id);
         // build redirect URL
         $redirectUrl = BackendModel::createURLForAction('Rooms') . '&report=deleted&var=' . urlencode($this->record['title'] . '&id=' . $this->record['id']);
         // item was deleted, so redirect
         $this->redirect($redirectUrl);
     } else {
         // something went wrong
         $this->redirect(BackendModel::createURLForAction('Rooms') . '&error=non-existing&id=' . $this->record['id']);
     }
 }
All Usage Examples Of Backend\Core\Engine\Model::deleteThumbnails