我正在尝试从语句中删除目录,而在使用PHP时,我似乎无法摆脱.
或..
目录。
$album_num = $_POST['album_num'];
$album_directory = "../../galleries";
$albums = array_reverse(scandir($album_directory));
$album = $albums[$album_num];
if($album) {
if($album !== "." || $album !== "..") { //This line here
$image = glob($album_directory . "/" . $album . "/*.jpg");
$image = explode("/", $image[0]);
$image = end($image);
echo $album . ":" . $image;
}
} else {
echo "halt";
}
if($album !== "." || $album !== "..")
行似乎不起作用。我需要逃脱点吗?
我能够从数组中删除它们吗?
答案 0 :(得分:0)
试试这个:
if($album) {
if($album !== "." && $album !== "..") { //This line here
$image = glob($album_directory . "/" . $album . "/*.jpg");
$image = explode("/", $image[0]);
$image = end($image);
echo $album . ":" . $image;
}
}
将if
条件从||
更改为&&
答案 1 :(得分:-2)
使用!=代替!==
我想你不希望这张专辑评价为!==
$album_num = $_POST['album_num'];
$album_directory = "../../galleries";
$albums = array_reverse(scandir($album_directory));
$album = $albums[$album_num];
if($album) {
if($album != "." || $album != "..") { //This line here
$image = glob($album_directory . "/" . $album . "/*.jpg");
$image = explode("/", $image[0]);
$image = end($image);
echo $album . ":" . $image;
}
} else {
echo "halt";
}