I’m making a website for users to upload files. Problem is, I would like my code to handle white spaces. When running the code, scandir cuts off any files containing spaces. So a file such as “My File.txt” is returned as “My”. What would be the best way of handling and preserving files that contain spaces in PHP?
public function scanDirAndSubdir($dir, &$out = []) {
$sun = scandir(($dir));
foreach ($sun as $a => $filename) {
$way = realpath($dir . DIRECTORY_SEPARATOR . $filename);
// List Files.
if (!is_dir($way)) {
$out[] = $way;
echo $filename;
// List Directories.
} else if ($filename != "." && $filename != "..") {
$this->scanDirAndSubdir($way, $out);
$out[] = ("$way/");
}
}
return $out;
}