简体   繁体   中英

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. 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.

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. for example:

$dirname = $mydir ;

where mydir returns the path of the current directory like:

$mydir = basename(getcwd()) . 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() ;

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.

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

EDIT : !!!

Just realized... :o !!!
The answer is:

$dirname = "./"  ;

omg

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

"I think I'm missing something here..." :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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