Jump to content

dameunmate

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dameunmate's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm trying to create an online web editor. It works fine for opening and writing files on the same server where the web editor is hosted, but I want it to be able to get_file_contents, fopen and fwrite files on a remote server, logging in with ftp_connect and ftp_login. I've noticed the functions ftp_get and ftp_fget but I'd rather not create another local file, if possible I want to open the remote file directly into a <texarea> then save it directly back to the remote server. Is this possible? So far I just get errors... Here's an example of the code I'm trying to combine, to retrieve the contents of a file on a remote server and put them in a <textarea>: <?php $conn = ftp_connect("ftp.domain.com"); ftp_login($conn, "username", "password"); ftp_pasv($conn, true); $filename='example.php'; // open file $fh = fopen($filename, "r") or die("Could not open file!"); // read file contents $datax = fread($fh, filesize($filename)) or die("Could not read file!"); $data=htmlspecialchars($datax); // close file fclose($fh); // close this connection ftp_close($conn); echo '<textarea cols="200%" rows="50">'.$data.'</textarea>'; ?> And another failed example: <?php $filename='editor.php'; $fh = fopen("ftp://username:password@domain.com/example.php", "r") or die("Could not open file!"); $datax = fread($fh, filesize($filename)) or die("Could not read file!"); $data=htmlspecialchars($datax); fclose($fh); echo '<textarea cols="200%" rows="50">'.$data.'</textarea>'; ?>
×
×
  • 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.