1

错误:readdir() 期望参数 1 是资源,给定字符串

$directorypremium = 'uploads/premium/'.text2url($pseudo_cookies).'/'; 

while($file = readdir($directorypremium)) {
        if($file != '.' AND $file != '..')
            {
            $taille_fichier = filesize($directory.$file); $taille_fichier = round($taille_fichier / 1000); $total_size = $total_size + $taille_fichier;
            }
        }

我的函数 text2url:

function text2url($chaine)
    {
    $chaine = htmlentities($chaine, ENT_NOQUOTES, 'utf-8');
    $chaine = preg_replace('#\&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring)\;#', '\1', $chaine);
    $chaine = preg_replace('#\&([A-za-z]{2})(?:lig)\;#', '\1', $chaine);
    $chaine = preg_replace('#\&[^;]+\;#', '', $chaine);
    $chaine = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $chaine);
    $chaine = str_replace('(', '', $chaine);
    $chaine = str_replace(')', '', $chaine);
    $chaine = str_replace('[', '', $chaine);
    $chaine = str_replace(']', '', $chaine);
    $chaine = str_replace('.', '-', $chaine);
    $chaine = trim($chaine);
    $chaine = str_replace(' ', '_', $chaine);

    return $chaine;
    }

我知道问题是 $chaine 是一个字符串值,但我无法解决问题以使其被 readdir 接受。有没有办法让 $chaine 对 readdir 函数有价值?

4

2 回答 2

3

readdir函数接受从该opendir函数获得的资源:

$dir = opendir($path);
while($file = readdir($dir)){
...

请参阅readdiropendir

于 2013-09-29T15:10:27.080 回答
1

readdir()接受文件句柄,而不是字符串:

引用手册

dir_handle : 以前用 . 打开的目录句柄资源opendir()。如果未指定目录句柄,则假定打开的最后一个链接opendir()。`

所以也许opendir()先使用?

于 2013-09-29T15:10:00.707 回答