Read all Images from folder PHP

The tutorial explains how to read all images from folder PHP. Here it shows how to get all the images from the folder shown below and get the content in the array as shown second figure.

Insert_Update_Acf_image_repeater_field_programmatically
read_all_images_from_folder_PHP

Please also refer the tutorial that explains how to upload the images in the wordpress media library and set that images to the ACF repeater image field .

function readDataFromImageFolder() {
    
    $imageFolderName = 14;
    $base = dirname(__FILE__);
    $dirname = $base.DS.'images'.DS.$imageFolderName.DS;
    $files = array();
    
    if (!file_exists($dirname)) {
        echo "The directory $dirname not exists.".PHP_EOL;
        exit;
    } else {
        echo "The directory $dirname exists.".PHP_EOL;
        $dh  = opendir( $dirname );
        
        while (false !== ($filename = readdir($dh))) {
            if ($filename === '.' || $filename === '..') continue;
            $files[] = $dirname.$filename;
        }
        uploadImages( $files );
    }

  //  echo '<pre>';
  //  print_r($files);die();

}

Share this Tutorial