无法删除目录中的文件


Unable to delete the file in a directory

我使用unlink()来删除服务器"galleryphoto/".$username目录下的文件。但每次执行时,文件都不会被删除。我想不出是什么地方出错了。由于编码是由jquery AJAX在PHP中的另一个页面调用的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>

尝试使用PHP的realpath

unlink(realpath($fileName));