簡體   English   中英

Codeigniter Unlink不起作用

[英]Codeigniter Unlink doesn't work

我想在刪除條目之前刪除圖像,所以我這樣做了

$query = $this->db->get_where('info', array("id" => $info_id));
        $results = $query->result_array();
        echo base_url().'theme/transport/images/services/thumbs/' . $results[0]['image'];die();
        unlink(base_url().'theme/transport/images/services/thumbs/' . $results[0]['image']);

但文件仍然存在。 它沒有取消鏈接。 我究竟做錯了什么?

采用

unlink('theme/transport/images/services/thumbs/' . $results[0]['image']);

代替

unlink(base_url().'theme/transport/images/services/thumbs/' . $results[0]['image']);

謝謝

首先刪除die()它終止程序的執行。然后嘗試

        $query = $this->db->get_where('info', array("id" => $info_id));
        $results = $query->result_array();
        echo base_url().'theme/transport/images/services/thumbs/' . $results[0]['image'];
        unlink(base_url().'theme/transport/images/services/thumbs/' . $results[0]['image']);

因為您正在嘗試取消鏈接文件。 你應該嘗試使用FCPATH

unlink(FCPATH .'theme/transport/images/services/thumbs/' . $results[0]['image']);

路徑函數定義

EXT: The PHP file extension
FCPATH: Path to the front controller (this file) (root of CI)
SELF: The name of THIS file (index.php)
BASEPATH: Path to the system folder
APPPATH: The path to the "application" folder

您也可以通過這種方式嘗試。 確保使用您執行PHP腳本的位置的路徑訪問映像文件。 我正在使用realpath()來獲取文件位置。

$images_location = realpath('theme/transport/images/services/thumbs/' . $results[0]['image']);
if (file_exists($images_location))
{
   unlink($images_location);
}

如果有任何問題,請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM