使用php传输zip文件产生0个字节

时间:2013-05-23 18:34:29

标签: php curl ftp

我已经做了好几天了,我尝试了很多不同的方法。我现在至少开始转移.zip文件,但是,它没有任何内容,只有文件的名称。
我有这个连接到文件所在的服务器(服务器a):

<?php
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: '.filesize($file));
    header('Content-Type: application/zip');
    ini_set('display_errors',"1");
    require_once('ftp.php');

    // set up basic connection
    $conn_id = ftp_ssl_connect($ftp_server);//ftp_connect

    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    ftp_pasv($conn_id, true);

    // check connection
    if ((! $conn_id ) || (! $login_result )) {
        echo "FTP connection has failed!" ;
        exit;
    } else {
        echo "Connected for user $ftp_user_name" ;
        echo "<br/>";
    }
?>

这一切都运行良好,echo是用户名。要传输我正在使用的.zip文件:

// using curl to get file
$url = $file;
$fh = fopen(basename($url), "wb");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);

curl_close($ch);

这会将文件名放在远程文件夹(服务器b)中,但其中没有任何内容,大小为0字节。如何获取整个文件的传输,以便我可以提取并使用这些信息?

0 个答案:

没有答案