我使用unlink()
删除服务器中"galleryphoto/".$username
目录中的文件。但每次执行时,文件都不会被删除。我无法弄清楚是什么错误。因为编码是一个PHP页面,由jquery AJAX在PHP中的另一个页面调用,我看不到错误。请帮帮我!
<?php
include('session.php');
include('db.php');
$new_user_id =$_SESSION['user_id'];
$cod= mysql_query("select user_login_id from user where user_id ='$new_user_id'");
$row=mysql_fetch_assoc($cod);
$username = $row['user_login_id'];
if(isset($_POST['file']) && is_array($_POST['file']))
{
$path = 'galleryphoto/'.$username;
$name = $_POST['file'];
foreach($name as $file1)
{
unlink($path."/".$file1) or die("Failed to delete file");
print_r(error_get_last());
}
//header("location: " . $_SERVER['REQUEST_URI']); //redirect after deleting files so the user can refresh without that resending post info message
}
?>
<form name="form1" action="" method="post">
<?php
//$path1='galleryphoto/'.$username;
$path = "galleryphoto/".$username;
$dir_handle = @opendir($path) or die("Unable to open folder");
while (false !== ($file = readdir($dir_handle))) {
if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;
echo "<input type='CHECKBOX' name='file[]' value='$path/$file'>";
// echo "<a href=$path/$file>$file<br><img src=$path/$file border=0></a><br>";
echo "<img src='$path/$file' alt='$file' border=0 height=300px width=300px><br />";
}
closedir($dir_handle);
?>
<input type="submit" name="Delete" value="Delete">
</form>