使用ajax代码删除上传的图像文件

I want to delete the images that are uploded one by one in php.

I used the following code for displaying the images.On clicking the delete button the image gets deleted from the upload folder.

Code

ImageLap.tpl.php

foreach ( $mainfile as $files ) {
     echo '<img src="'.$files.'" width="100" height="65">';
     echo '<input type="hidden" value="'.$files.'" name="delete_file" />';
     echo '<input type="submit" value="Delete image" />';
 }

ImageLap.php

  if ( array_key_exists ('delete_file', $_POST ) ) {
       $filename = $_POST['delete_file'];
       if ( file_exists ( $filename ) ) {
           unlink( $filename );
           echo 'File '.$filename.' has been deleted';
       }
  }

This code is working well.But the page has to be refreshed on each file deletion. I need a help to delete the files without refreshing the page.I heard that ajax is used for this.But I don't have knowledge in ajax

Please do help me to implement ajax in this code.

查看全部
donglao4370
donglao4370
2013/09/16 04:43
  • php
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复