PHP glob a directory going wrong in some cases why? -


i have mistery php code going wrong in cases , don't understand why. current code displaying photos related client range.

example: pick inside folder pictures 300 310 , display them.

example of photos names inside folder: c20_0385, c20_0386, c20_0389, c20_0400...

current php code: photos 385 420.

$start = 385: $end = 420;  $dirname = "smallphotos/$jour_creation - $date_creation/$session/$dossier";  $filenames = glob("$dirname/*{" . implode(",", range($start, $end)) . "}*", glob_brace);  foreach ($filenames $filename) { echo "<img class=\"img-responsive\" src=\"$filename\" alt=\"$filename\">"; } 

that works , if $start = 385; $end = 450;

it write errors:

warning: glob(): pattern exceeds maximum allowed length of 260 characters warning: invalid argument supplied foreach() 

if $start = 385; $end = 435; shows whole folder c20_503.jpg

it looks small range more or less 40 photos job more going wrong.

the error states glob pattern cannot longer 260 characters; you're going have use an alternative approach:

$filenames = array(); $dir = opendir( $dirname ); while (false !== ($file = readdir($dir))) {     if ( is_file( $file ) && preg_match( "/^.*?_(\d+)/", $file, $m )       && $m[1] >= $start && $m[1] <= $end     )         $filenames[] = "$dirname/$file"; } closedir($handle); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -