tibi888
tibi888

Reputation: 23

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

Upvotes: 0

Views: 1324

Answers (1)

Sasa Jovanovic
Sasa Jovanovic

Reputation: 334

Try

$parent = dirname(__DIR__);

http://php.net/manual/en/language.constants.predefined.php

Upvotes: 1

Related Questions