Jump to content

[SOLVED] file_get_contents help


sasori

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.