kennybjr87's avatar

Deleting files uploaded to storage on sharedhost

I created a project locally, upload and delete worked fine. Now since uploading to a shared host, I'm still able to upload a file but I can't find a way to delete the file from the storage any suggestions? Currently, I'm using the unlink() I have no way of running the storage:link

0 likes
1 reply
jlrdw's avatar

I use this, here I delete a record and an associated image file, works on shared hosting for me.

    function delete()
    {
        if ($this->chklog() == 'notlogged') {
            Url::redirect('admin');
        }
        $id = $_GET['id'];
        $this->Dog->delete($id);
        $dfile = "NO File";
        if (!empty($_GET['tmppic'])) {
            $tmppic = $_GET['tmppic'];
            $target_path = ROOT . 'upload/imgdogs/';
            $tmpfile = $target_path . $tmppic;

            if (is_file($tmpfile)) {
                if (!unlink($tmpfile)) {
                    $dfile = "Error deleting file";
                } else {
                    $dfile = "File deleted";
                }
            }
        }
        $data["msg"] = $dfile;
        $path = 'dog/imgdel';
        View::render($path, $data);
        
    }

Adjust to laravel version you use as needed.

Please or to participate in this conversation.