2011-04-14 107 views
0

为什么我的filesize()方法无法正常工作?我的路径适用于fread()file()方法,但它不会承认filesize()上的路径。为什么不?我的正确道路应该是什么?为什么不能使用我的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"; 
?> 
+0

请注意,您在1号线开手柄'lesson5.txt'但随后通过vocabulary5.txt'的'文件大小在2号线。错误或功能? – horatio 2011-04-14 20:49:22

回答

5

由于您尝试读取的文件是通过远程请求而非本地文件,因此它会显着改变您想要读取该数据的方式。根据fread() manual page,您需要以块的形式读取文件。或者,尝试使用file_get_contents()应该简化代码:

$lessonDescription = file_get_contents('http://nova.umuc.edu/~ct386a28/lovej2ee/exercise5/content/vocabulary5.txt'); 
echo $lessonDescription; 
+0

Sweeeeeet!感谢Cadaeic!这就是诀窍:) – Mike 2011-04-14 18:27:48

+2

很高兴提供帮助。请记住投票并将答案标记为接受,一旦你找到了你要找的东西。 – 2011-04-14 18:30:51

相关问题