Edit: After testing your posted code with my own system path, there were no problems.
Check to make sure you have your system path correct.
Use phpinfo();
inside a file, look under Environment, then DOCUMENT_ROOT.
- If you do not have access/privilege to use
phpinfo()
, then login to your admin panel, and/or contact your hosting provider for your system path, should that be the case.
Use error reporting http://php.net/manual/en/function.error-reporting.php
"All dirs have chmod 777"
- That isn't the safest setting. Use 755 for folders and 644 for files.
Original answer before edit:
This is what I use and would be better if your folder happens to contain files other than images.
- Sidenote: It's best for a folder to have an index file, otherwise someone may find the folder and have a peek at what's inside it, that's if you haven't taken care of this otherwise.
Ensure that the path is correct.
$imagesDir = '/path/to/files';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE | GLOB_NOSORT);
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Displaying errors should only be done in staging, and never production.
Reference: