public function set_array($set_value) {
/*set empty class*/
$tempclass = new stdClass();
/*full Image path src*/
$search_dir = "/domain/img/company/Image1-000000-016";
/*open dir*/
$images = glob("$search_dir/*.*");
sort($images);
/*loop thought dir and get first Image*/
if (count($images) > 0) {
/*get product imagepath and set as src*/
$tempclass->src = $images[0];
/*return all data to array*/
$this->Imagedata[] = clone($tempclass);
}
}
My intention was to check my folder image and store first image to Imagedata[]
, but I keep checking the Imagedata[]
is empty, I don't know why. I checked the folderpath as well, it is correct so what did I do wrong?
maybe because you store your files in $files
variable and then check for $images
variable which is undefined?
I really suggest you to spend some time into turning on E_NOTICE errors in your PHP environment, they help you a great deal in catching this kind of mistakes (it happens to everyone)
After Question Edited:
I think the best way to get files in a directory is :
$directory = "/domain/img/company/Image1-000000-016";
$images = scandir ($directory);
$firstImage = $directory . $files[2];
//$tempclass->src = $firstImage;
if this didn't work check directory permission and check if exists at all?
Old Answer:
You are doing just something small wrong! There is no $images variable at all! I think :
if (count($images) > 0) {
$tempclass->src = $images[0];
//....
}
Must be :
if (count($files) > 0) {
$tempclass->src = $files[0];
//....
}