PHPファイルに次のコードがあります-$uploaded_files変数を初期化してから、getDirectoryを呼び出します(これも以下にリストされています)。
vardump($ uploaded_files)を実行すると、変数の内容が表示されますが、何らかの理由<?php echo $uploaded_files; ?>
でHTMLファイルを呼び出すと、「ファイルが見つかりません」というメッセージが表示されます。何か間違ったことをしていますか?
誰かが助けることができますか?ありがとうございました。
/** LIST UPLOADED FILES **/
$uploaded_files = "";
getDirectory( Settings::$uploadFolder );
// Check if the uploaded_files variable is empty
if(strlen($uploaded_files) == 0)
{
$uploaded_files = "<li><em>No files found</em></li>";
}
getDirectory関数:
function getDirectory( $path = '.', $level = 0 )
{
// Directories to ignore when listing output. Many hosts
// will deny PHP access to the cgi-bin.
$ignore = array( 'cgi-bin', '.', '..' );
// Open the directory to the handle $dh
$dh = @opendir( $path );
// Loop through the directory
while( false !== ( $file = readdir( $dh ) ) ){
// Check that this file is not to be ignored
if( !in_array( $file, $ignore ) ){
// Its a directory, so we need to keep reading down...
if( is_dir( "$path/$file" ) ){
// We are now inside a directory
// Re-call this same function but on a new directory.
// this is what makes function recursive.
getDirectory( "$path/$file", ($level+1) );
}
else {
// Just print out the filename
// echo "$file<br />";
$singleSlashPath = str_replace("uploads//", "uploads/", $path);
if ($path == "uploads/") {
$filename = "$path$file";
}
else $filename = "$singleSlashPath/$file";
$parts = explode("_", $file);
$size = formatBytes(filesize($filename));
$added = date("m/d/Y", $parts[0]);
$origName = $parts[1];
$filetype = getFileType(substr($file, strlen($file) - 4));
$uploaded_files .= "<li class=\"$filetype\"><a href=\"$filename\">$origName</a> $size - $added</li>\n";
// var_dump($uploaded_files);
}
}
}
// Close the directory handle
closedir( $dh );
}