简体   繁体   English

PHP scandir不适用于相对路径

[英]PHP scandir not working for relative path

I have a folder called images in my current directory but when I try to run the code below I get the following error: 我的当前目录中有一个名为images的文件夹,但是当我尝试运行以下代码时,出现以下错误:

PHP Warning: scandir(../images,../images): The system cannot find the file specified. (code: 2) in C:\\Program Files (x86)\\Ampps\\www\\dev\\php\\recolor_png\\dir.php on line 4

<?php
$dir = "../images";

$a = scandir($dir);

print_r($a);

I've tried every variation of the path I can think of ( images, /images/, "images", 'images' etc. but no joy. 我已经尝试过可以想到的路径的每一种变化( images, /images/, "images", 'images'等,但没有喜悦。

var_dump (is_dir('/images')); also gives false 也给false

Please help? 请帮忙?

尝试使用__DIR__常量

$dir = __DIR__ . "/images";

I think your $dir is not correct.you can use 我认为您的$ dir不正确。您可以使用

$dir = __DIR__ . "/images";

or 要么

$dir = "./images";

Both are working. 两者都在工作。 If its not working show me your image folder structure. 如果它不起作用,请告诉我您的图像文件夹结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM