为什么我的filesize()方法不起作用?

Mik*_*ike 0 php fopen filesize fread

为什么我的filesize()方法不起作用?我的路径适用于fread()file()方法,但它不会承认路径filesize().为什么不?我的正确道路应该是什么?

<?php     
    $strLessonDescription = fopen("http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/lesson5.txt", "r") 
                            or die ("Error - lesson5.txt cannot be opened");
    $lessonDescription = fread($strLessonDescription, 
                               filesize("http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/vocabulary5.txt"));
    fclose($strLessonDescription);

    echo $lessonDescription;        
    $arrLessonVocabulary = array();
    $arrLessonVocabulary = file("http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/vocabulary5.txt");

    if (arrLessonVocabulary == NULL)
        print "Error - vocabulary5.txt cannot be opened";
?>
Run Code Online (Sandbox Code Playgroud)

Tay*_*ing 5

由于您尝试读取的文件是通过远程请求而不是本地文件,因此它会显着改变您希望读取该数据的方式.根据fread()手册页,您需要以块的形式读取文件.或者,尝试使用file_get_contents()来简化代码:

$lessonDescription = file_get_contents('http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/vocabulary5.txt');
echo $lessonDescription;
Run Code Online (Sandbox Code Playgroud)

  • 乐意效劳.一旦找到了您正在寻找的内容,请记得投票并将答案标记为已接受. (2认同)