3868 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 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!

30 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
Nielsk says

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

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

3868 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 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);
?>
30 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
Nielsk says

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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by