• Reading Contents of .txt
    8 replies, posted
I'm trying to get the contents of a .txt like this: [php]$bfile = fopen( "http://www.robertandsherman.co.uk/botbattle/bots/bot" . $botid . ".txt", "r" ); $raw = fread( $bfile, filesize( $bfile )); fclose( $bfile ); echo( "contents: " . $raw );[/php] But all I get is "contents: " with nothing next to it. The file definitely exists in the place I specified, so what have I done wrong?
[url]http://ca2.php.net/file_get_contents[/url]
[QUOTE=gngbng;18101927][url]http://ca2.php.net/file_get_contents[/url][/QUOTE] Thanks
You are using [url=http://php.net/manual/en/function.filesize.php]filesize[/url] wrong.
[QUOTE=high6;18102817]You are using [url=http://php.net/manual/en/function.filesize.php]filesize[/url] wrong.[/QUOTE] Thanks, at least I know what I did wrong with the old method now :D
[QUOTE=high6;18102817]You are using [url=http://php.net/manual/en/function.filesize.php]filesize[/url] wrong.[/QUOTE] No he isn't, for fread you need to specify how many bytes to read from the file. In this case using filesize($file) reads the entire file. I personally don't see a problem with that script, but I think it may be because you've specified a complete URL where I think it requires a relative path. file_get_contents allows you to use full URLs, hence its ability to fetch data from remote hosts.
[QUOTE=User.;18103162]No he isn't, for fread you need to specify how many bytes to read from the file. In this case using filesize($file) reads the entire file. I personally don't see a problem with that script, but I think it may be because you've specified a complete URL where I think it requires a relative path. file_get_contents allows you to use full URLs, hence its ability to fetch data from remote hosts.[/QUOTE] He was doing filesize( file handle ) and not filesize( file.txt )
I thought it throws a warning if you try using filesize() on an external file
[QUOTE=efeX;18104488]I thought it throws a warning if you try using filesize() on an external file[/QUOTE] I think it does.
Sorry, you need to Log In to post a reply to this thread.