Reputation: 356
Hi Stackoverflow masters, I have problem with glob function php.
$gallery_full = glob("/var/www/home.com/uplo_1/*.*",GLOB_NOSORT);
print_r($gallery_full);
This lines returns me nothing. All dirs have chmod 777. In uplo_1 there are jpg and png files. Any one know how to run it ?
Upvotes: 2
Views: 1487
Reputation: 74217
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.
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"
Original answer before edit:
This is what I use and would be better if your folder happens to contain files other than images.
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:
Upvotes: 4
Reputation: 91
When I use glob
I prepend the DOCUMENT_ROOT first, like this:
$fileCount = $_SERVER['DOCUMENT_ROOT'] . '/path/to/file.ext';
echo $fileCount;
This should work.
Upvotes: 1