2017-02-28 69 views
1

我想刪除條目之前刪除的圖像,所以我做了這個笨取消鏈接不起作用

$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']); 

但文件仍然存在。它不會取消鏈接。我究竟做錯了什麼?

回答

1

要因爲您試圖取消鏈接文件。你應該嘗試使用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 
+0

Thankyou它正在工作。 –

1

使用

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

而不是

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

感謝

1

首先拆下die()它終止program.Then的執行嘗試

 $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']); 
0

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

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

請讓我知道是否有任何問題。