-1

ボタンを使用して画像を削除しようとしています。

私が使用するボタンをクリックすると onClick"'.delete_files(assets/uploads/.$image->filename).'"

しかし、何も起こっていません。画像は、ボタンをクリックする前の状態のままです。私がするときprint_r($image->filename)、ページに表示されている私の画像の3つの名前を取得します。

これは私のコードです:

<table class="images">
    <tr>
    <br/>
    <? foreach($images as $image) { ?>
    <td>
    <a href="assets/uploads/<?= $image->filename ?>" rel="lightbox" title="<?= $image->filename; ?>">
    <img src="<?php echo base_url();?>assets/uploads/<?= $image->filename; ?>" width="200px">
    </a>
<?= '<input type="button" value="Delete" onclick"'.delete_files('assets/uploads/'.$image->filename).'"><br/>'; ?>
    </td>
    <? } ?>
    </tr>
</table>

その道は正しいのだろうか。しかし、資産フォルダーは私のルートにあります。httpdocs/assets/uploads で、私の codeigniter フォルダーは httpdocs/application/ にあるので、うまくいくはずです。

4

2 に答える 2

0

onclickの属性でphp関数を呼び出していると確信していますが、これは間違っているので、直接関数をbutton呼び出すことはできませんserver sidehtml element's attribute

codeigniterコントローラーで関数を作成し、anchorボタンの代わりにタグを配置します

<table class="images">
<tr>
<br/>
<? foreach($images as $image) { ?>
<td>
<a href="assets/uploads/<?= $image->filename ?>" rel="lightbox" title="<?= $image->filename; ?>">
<img src="<?php echo base_url();?>assets/uploads/<?= $image->filename; ?>" width="200px">
</a>

<?= '<a  title="Delete" href="'.site_url().'controller/delete_files/'.$image->filename).'"><br/>'; ?>
</td>
<? } ?>
</tr>
</table>

コントローラーで関数を作成しますdelete_files()

 function delete_files($image_name){     
 // write the code to delete or unlink $image_name
 unlink('ROOT PATH'.$image_name);
 }
于 2013-05-22T13:28:30.987 に答える
0

使用する

unlink('./path/to/directory/');
于 2016-03-16T11:53:52.387 に答える