CodeCanyon

PHP Help Please :)

3867 posts
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 100 and 499 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 6-7 years
+4 more
flashjunkie says

Hey Guys,

Trying to get scandir() working and need a little help…

I’m able to get scandir() to work when the $dir is a subdirectory or the current scripts location however im trying to access a folder elsewhere on the server but when I try to locate it using a URL i’m getting errors…

ie:

Script location – http://mysite.com/scripts/getFileNames.php

Directory Location – http://mysite.com/images/thumbnails

<?php
$dir    = 'ResourceImages/Previews/1';
$files1 = scandir($dir);
print_r($files1);
?>

Thanks guys!

25 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Netherlands
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
Nielsk says

You can’t use external URLs with scandir().

Try using the full path on the server to retrieve the files.

3867 posts
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 100 and 499 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 6-7 years
+4 more
flashjunkie says

Hi Nielsk,

Thanks for that, managed to get it working on localhost with…

<?php

$dir = $_SERVER['DOCUMENT_ROOT'];
$dir .= '/SITE-DEBUG/Images/Previews/1';
$files = array_diff(scandir($dir), array('..', '.'));

print_r($files);
?>
25 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Netherlands
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
Nielsk says

No problem :) You could also use http://nl3.php.net/manual/en/function.glob.php for that by the way

by
by
by
by
by