note 86104 modified in function.fstat by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Another ftp_get_contents() approach, using a temperary stream handler. Returns file contents of remote file as string. 

<?php
function ftp_get_contents ($conn_id, $remote_filename) {
    //Create temp handler:
    $tempHandle = fopen('php://temp', 'r+');

    //Get file from FTP assuming that it exists:
    ftp_fget($conn_id, $tempHandle, $remote_filename, FTP_ASCII, 0));

    //Getting detailed stats to check filesize:
    $fstats = fstat($tempHandle);

    return fread($tempHandle, $fstats['size']);
}
?>

(It is recommended to add some error handling)

--was--
Another ftp_get_contents() approach, using a temperary stream handler. Returns file contents of remote file as string. 

function ftp_get_contents ($conn_id, $remote_filename) {
    //Create temp handler:
    $tempHandle = fopen('php://temp', 'r+');

    //Get file from FTP assuming that it exists:
    ftp_fget($conn_id, $tempHandle, $remote_filename, FTP_ASCII, 0));

    //Getting detailed stats to check filesize:
    $fstats = fstat($tempHandle);

    return fread($tempHandle, $fstats['size']);
}

(It is recommended to add some error handling)

http://php.net/manual/en/function.fstat.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.