Jump to content

Adding to Arrays


zfred09

Recommended Posts

Can you use regular expressions?  Like say...."find instances where filename does NOT contain a period"....thus implying that it's a folder...

 

$list = glob("(!.|*.jpeg)");

 

or, do it twice...but with the 2nd time, using only directories...

 

$list = glob("*.jpeg");
$list2 = glob("*", GLOB_ONLYDIR);

Link to comment
https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-246815
Share on other sites

It will work

<?php

$dir = "/path/to/dir/";

// Open a known directory, and proceed to read its contents

if (is_dir($dir)) {

if ($dh = opendir($dir)) {

while (($file = readdir($dh)) !== false) {

if(getimagesize($file)){

$image_array[] = $file;

}

}

closedir($dh);

}

}

print_r($image_array);

?>Here getimagesize() is making sure weather its an Image file or not.

Sorry cannot use [ php ][ / php ] here

Link to comment
https://forums.phpfreaks.com/topic/50284-adding-to-arrays/#findComment-247001
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.