上位のディレクトリからファイルを削除する際に問題が発生しました。この投稿を見つけて試しましたが、うまくいきませんでした。
Gmailドットコムでのgotdalife2008年9月25日02:04
アクセス許可の拒否エラーで問題が発生した場合は、作業ディレクトリの階層の上位にあるフォルダにあるファイルを削除しようとしたとき(つまり、「../」で始まるパスを削除しようとしたとき)に発生することがあります。 )。
したがって、この問題を回避するには、chdir()を使用して、作業ディレクトリを、リンクを解除するファイルが配置されているフォルダに変更します。
<?php
> $old = getcwd(); // Save the current directory
> chdir($path_to_file);
> unlink($filename);
> chdir($old); // Restore the old working directory ?>
これが私が現在持っているコードです:
session_start();
if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] !=md5($_SERVER['HTTP_USER_AGENT']))){
require_once ('includes/login_functions.inc.php');
$url = absolute_url();
header("Location: $url");
exit();
}
$folder = $_GET['folder'];
$filename = $_GET['name'];
$path = "../gallery/photos/$folder";
if (isset($_POST['submitted'])) {
if ($_POST['sure'] == 'Yes') {
$old = getcwd(); // Save the current directory
chdir($path);
unlink($filename);
chdir($old); // Restore the old working directory
}
else{
echo '<p>The photo has NOT been deleted.</p>';
}
}
エラーメッセージが表示されます:
警告:unlink()[function.unlink]:37行目のJ:\ xampp \ htdocs \ bunker \ admin\delete_file.phpにエラーはありません
37行目:
unlink($filename);
誰かが私が間違ったことを見ることができますか?