This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

kattsoff
kattsoff

After delete file it only deleting record from DB, but file isn't deleting from server. As a result, the server accumulates a large number of unnecessary files. Update this widget, please. It seems be more properly.

d.negativa
kattsoff
kattsoff

It would be convenient to add MaxFilesize as a parameter to this widget. Like:


avatar:
  label: Avatar
  type: fileupload
  mode: image
  imageHeight: 260
  imageWidth: 260
  maxSize: 15728640
Scott
Scott

@kattsoff, deleting the file model should trigger an afterDelete() method to remove the file from storage... Are you sure you're triggering the file deletion from your model?

public function afterDelete()
{
    $this->file->delete();
}

That should trigger this method on the file model https://github.com/octobercms/library/blob/master/src/Database/Attach/File.php#L444-L457

Last updated

kattsoff
kattsoff

@Scott, I'am talking about fileupload formwidget in /modules/backend/formwidgets/Fileupload.php. In this Fileupload class we have only this:


/**
     * Removes a file attachment.
     */
    public function onRemoveAttachment()
    {
        if (($file_id = post('file_id')) && ($file = File::find($file_id))) {
            $this->getRelationObject()->remove($file, $this->sessionKey);
        }
    }

I think that in this class it's more correctly deleting file from folder after we deleted it from DB. I know that in File model we have file delete function like you written above. Something like it I mean:

/**
     * Removes a file attachment.
     */
    public function onRemoveAttachment()
    {
        if (($file_id = post('file_id')) && ($file = File::find($file_id))) {
            $this->getRelationObject()->remove($file, $this->sessionKey);
        }
        $file->delete();
    }

Last updated

kattsoff
kattsoff

In Fileupload.php for deleting crop images and files.

/**
     * Removes a file attachment.
     */
    public function onRemoveAttachment()
    {
        if (($file_id = post('file_id')) && ($file = File::find($file_id))) {
            $this->getRelationObject()->remove($file, $this->sessionKey);
            $file->afterDelete();
        }
    }

Last updated

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.