简体   繁体   English

如何将父目录变量添加到 scandir (PHP)

[英]How to add parent dir variable to scandir (PHP)

Hi sorry this is probably a really newbie question, but I'm searching for the answer for 2 days now and no luck.嗨,抱歉,这可能是一个真正的新手问题,但我现在正在寻找答案 2 天,但没有运气。 I'm using a script what generates an image gallery from an uploaded folder.我正在使用从上传的文件夹生成图片库的脚本。 Script info: Tim-thumb script created by Tim McDaniels and Darren Hoyt with tweaks by Ben Gillbanks.脚本信息:Tim-thumb 脚本由 Tim McDaniels 和 Darren Hoyt 创建,并由 Ben Gillbanks 进行调整。

You need to add the directory name what contains the images to the script like:您需要将包含图像的目录名称添加到脚本中,例如:

 $dirname = "images/"  ;
    $images = scandir($dirname);
    shuffle($images);

What I'm trying to do is make the script work automatically if i upload it in a new folder with new images so I don't need to add the $dirname every time I upload a gallery.如果我将脚本上传到包含新图像的新文件夹中,我想要做的是让脚本自动工作,这样我就不需要每次上传图库时都添加 $dirname。 for example:例如:

$dirname = $mydir ; $dirname = $mydir ;

where mydir returns the path of the current directory like:其中 mydir 返回当前目录的路径,如:

$mydir = basename(getcwd()) . $mydir = basename(getcwd()) 。 DIRECTORY_SEPARATOR ; DIRECTORY_SEPARATOR ;

but it's not working.但它不起作用。

also tried to make it work from a function:还试图让它从一个函数工作:

function current_dir()
{$path = dirname($_SERVER[PHP_SELF]);$position = strrpos($path,'/') + 1;print substr($path,$position);}   

than -->比-->

$dirname = current_dir() ; $dirname = current_dir() ;

but no luck.但没有运气。 I think I'm missing something here, I'm a totally noob and maybe it's just a syntax issue but can't make it work.我想我在这里遗漏了一些东西,我完全是个菜鸟,也许这只是一个语法问题,但无法使其工作。 I always get [function.scandir]: failed to open dir ... or creates the gallery but the images not working (I see only alt tags) thank you for any help.我总是得到 [function.scandir]: failed to open dir ... 或创建图库但图像不起作用(我只看到 alt 标签)感谢您的帮助。

>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>

EDIT : !!!编辑 : !!!

Just realized... :o !!!刚刚意识到... :o !!!
The answer is:答案是:

$dirname = "./"  ;

omg我的天啊

<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<

"I think I'm missing something here..." :D “我想我在这里遗漏了一些东西......”:D

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

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