note 72615 added to ref.ftp
| From: | ras | Date: | Fri, 26 Jan 2007 09:11:06 +0000 |
| Subject: | note 72615 added to ref.ftp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122216@lists.php.net to get a copy of this message | ||
A function to get a remote file and return it's contents, instead of saving to a local file,
was missing - here it is:
function ftp_fetch($ftp_stream, $remote_file) {
ob_end_flush();
ob_start();
$out = fopen('php://output', 'w');
if (!ftp_fget($ftp_stream, $out, $remote_file, FTP_ASCII)) die('Unable to get file: ' .
$remote_file);
fclose($out);
$data = ob_get_clean();
return $data;
}
It works the same as ftp_get(), but instead returns the contents of the remote file - for example:
$ftp = ftp_connect('my.server.com', 21, 60);
ftp_login($ftp, 'username', 'password');
$data = ftp_fetch($ftp, 'path/to/remote.file');
echo $data;
Note, I use it to fetch text-files from a server - if you need to fetch binary files, change
FTP_ASCII to FTP_BINARY .. but most likely, getting files to memory is only useful for smaller
files, e.g. plain text, xml, etc.
----
Server IP: 195.184.96.15
Probable Submitter: 82.143.224.4
----
Manual Page -- http://www.php.net/manual/en/ref.ftp.php
Edit -- https://master.php.net/note/edit/72615
Del: integrated -- https://master.php.net/note/delete/72615/integrated
Del: useless -- https://master.php.net/note/delete/72615/useless
Del: bad code -- https://master.php.net/note/delete/72615/bad+code
Del: spam -- https://master.php.net/note/delete/72615/spam
Del: non-english -- https://master.php.net/note/delete/72615/non-english
Del: in docs -- https://master.php.net/note/delete/72615/in+docs
Del: other reasons-- https://master.php.net/note/delete/72615
Reject -- https://master.php.net/note/reject/72615
Search -- https://master.php.net/manage/user-notes.php