Jump to content

[SOLVED] scandir()


dreamwest

Recommended Posts

is it possible to scandir a random file??

 

This code selects the first file found

$dir = '/htdocs/user/site.com/thumbs/';
foreach(scandir($dir) as $file){

if (strtolower(substr($file, -4)) == '.jpg') {

	if (file_exists($dir . $file)) {

	$image = "/thumbs/".$file;
	echo $image;

	} else {
	//default image
	echo "There was an error getting the thumbnail ";
	}
}
}//end foreach

Link to comment
https://forums.phpfreaks.com/topic/165681-solved-scandir/
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.