Listing all images in a directory using PHP

前端 未结 8 767
悲&欢浪女
悲&欢浪女 2021-01-04 08:39

I have the code below that lists all the images in a folder, the problem is that it finds some files ( a . and a ..) that I am not sure what they are so I a

8条回答
  •  心在旅途
    2021-01-04 08:44

    while (($file = readdir($handle)) !== false) {
        if (
            ($file == '.')||
            ($file == '..')
        ) {
            continue;
        }
        $newfile = str_replace(' ', '_', $file);
        rename(IMAGEPATH . $file, IMAGEPATH . $newfile);
        $directoryfiles[] = $newfile;
    }
    

提交回复
热议问题