sasori Posted August 2, 2008 Share Posted August 2, 2008 i don't get how to use the file_get_contents function, my code produces error <?php $dir = ftp_connect("www.yourdomain.com"); $user = "username"; $pwd = "password"; $login = ftp_login($dir,$user,$pwd); $filesarray = ftp_nlist($dir,"www/"); $fh = fopen('http://www.yourdomain.com/marry_poppins.html','r') or die ("can't open file"); while(!feof($fh)) { $readline = file_get_contents($fh); echo $readline; } ftp_close($dir); fclose($fh); ?> Link to comment https://forums.phpfreaks.com/topic/117829-solved-file_get_contents-help/ Share on other sites More sharing options...
Tandem Posted August 2, 2008 Share Posted August 2, 2008 What does the error say? Link to comment https://forums.phpfreaks.com/topic/117829-solved-file_get_contents-help/#findComment-606050 Share on other sites More sharing options...
sasori Posted August 2, 2008 Author Share Posted August 2, 2008 What does the error say? Warning: file_get_contents() expects parameter 1 to be string, resource given in C:\wamp\www\test2\index2.php on line 67 (where in Line 67 = $readline = file_get_contents($fh); ) Link to comment https://forums.phpfreaks.com/topic/117829-solved-file_get_contents-help/#findComment-606054 Share on other sites More sharing options...
.josh Posted August 2, 2008 Share Posted August 2, 2008 fopen opens a resource stream. You would use fread to read the contents and fwrite to write the contents. file_get_contents requires the actual file name and it reads the file into a giant string of the file's contents, so you don't really use file_get_contents with fopen. You'd really be using one or the other. Link to comment https://forums.phpfreaks.com/topic/117829-solved-file_get_contents-help/#findComment-606056 Share on other sites More sharing options...
JasonLewis Posted August 2, 2008 Share Posted August 2, 2008 Read up on file_get_contents(). The error is self explanatory. You passed a resource to file_get_contents(), not a string. You need to call it like: $contents = file_get_contents("textdoc.txt"); Link to comment https://forums.phpfreaks.com/topic/117829-solved-file_get_contents-help/#findComment-606058 Share on other sites More sharing options...
sasori Posted August 2, 2008 Author Share Posted August 2, 2008 fopen opens a resource stream. You would use fread to read the contents and fwrite to write the contents. file_get_contents requires the actual file name and it reads the file into a giant string of the file's contents, so you don't really use file_get_contents with fopen. You'd really be using one or the other. it works fine now..thanks <?php $dir = ftp_connect("domain.test.org"); $user = "user"; $pwd = "password"; $login = ftp_login($dir,$user,$pwd); $filesarray = ftp_nlist($dir,"www/"); $fh = file_get_contents('http://www.domain.com/marry_poppins.html'); echo $fh; ftp_close($dir); fclose($fh); ?> Link to comment https://forums.phpfreaks.com/topic/117829-solved-file_get_contents-help/#findComment-606059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.