0

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

tibi888
  • 23
  • 1
  • 5
  • 2
    Possible duplicate of [Get parent directory of running script](http://stackoverflow.com/questions/1882044/get-parent-directory-of-running-script) – nl-x May 10 '16 at 15:05
  • yes but the problem is, I dont get the images, only the alt tags show up this way. – tibi888 May 10 '16 at 15:39

1 Answers1

1

Try

$parent = dirname(__DIR__);

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

Sasa Jovanovic
  • 324
  • 2
  • 14
  • Thank you, but just like above, I dont get the images, only the alt tags show up this way. – tibi888 May 10 '16 at 15:41
  • Can you see image buy typing URL in browser? If not check folder privileges – Sasa Jovanovic May 10 '16 at 19:31
  • Yes, thanks again for the help, i found a solution.But if I use what I asked here, than the gallery contains all files in the directory, and I need only the images.so I changed the directory structure.It works now, just not how I wanted first.Have a great day, thanks again. @sasa – tibi888 May 10 '16 at 20:50