亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

codeigniter 從文件夾中刪除文件

codeigniter 從文件夾中刪除文件

PHP
蕭十郎 2022-07-29 16:38:03
請誰能幫我我想從文件夾codeigniter中刪除文件這是我的控制器 public function delete($id = false) {        if (!$id)            show_404();        $this->{$this->model}->{$this->_primary_key} = $id;        $data['item'] = $this->{$this->model}->get();        if (!$data['item'])            show_404();        $this->{$this->model}->delete();        redirect('admin/' . $this->module);    }    public function image($var, $id) {        $config['upload_path'] = './cdn/sliders/';        $config['allowed_types'] = 'gif|jpg|png|jpeg';        $this->load->library('upload', $config);        if ($this->upload->do_upload('image')) {            $data = $this->upload->data();            if ($data['file_name'])                $this->{$this->model}->image = $data['file_name'];        }        return true;    }
查看完整描述

3 回答

?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

就像是


public function delete_video($id)

{

    $this->db->where('id', $id);

    $this->db->select('video');

    $video_name = $this->db->get('vs_videos')->row_array();

    if ($video_name) {

        @unlink('./vs_asset/videos/' . $video_name['video']);


        $this->db->where('id', $id)

            ->delete('vs_videos');

        $result = $this->db->affected_rows();

        return $result;

    } else {

        return;

    }

}


查看完整回答
反對 回復 2022-07-29
?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

$filename = file_name_with_full_path

您可以使用 unlink($filename) 函數在 php 中刪除文件

請查看以下鏈接了解詳情

https://www.w3schools.com/php/func_filesystem_unlink.asp


查看完整回答
反對 回復 2022-07-29
?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

非常感謝,我得到了答案


這里是如何工作的。


public function delete($id = null) {


        if (!$id)

            show_404();

        $this->{$this->model}->{$this->_primary_key} = $id;

        $path = './cdn/projects/';

        $data['item'] = $this->{$this->model}->get();

            if (!$data['item'])

                show_404();

        @unlink($path.$data['item']->image);

        $this->{$this->model}->delete();

        redirect('admin/' . $this->module);

    }


查看完整回答
反對 回復 2022-07-29
  • 3 回答
  • 0 關注
  • 165 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號