2017-02-28 34 views
1

動作しない私は、エントリを削除する前に画像を削除したいので、私はこのCodeIgniterのリンク解除は

$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

をしてみてください終了しますファイルのリンクを解除しようとしているためです。あなたは

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

パス機能の使用FCPATHを試してみてくださいあなたはまた、この方法で試してみることができ

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

ありがとうございます。 –

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); 
} 

問題がある場合は教えてください。

関連する問題