如何使用Curl将文件从另一个服务器上传到另一个服务器? [英] How to upload a file from another server to another server using Curl?

查看:179
本文介绍了如何使用Curl将文件从另一个服务器上传到另一个服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Curl在Shell脚本和PHP中将文件从另一个服务器上传到另一个服务器?

How to upload a file from another server to another server using Curl in Shell script and PHP?

我有一个txt文件存储在服务器脚本存储,现在,我想要该txt文件上传到另一个服务器的特定文件夹。 2.服务器已经连接。

I have a txt file is stored in the server where the Shell script stored and now, I want that txt file to be uploaded to the specific folder of another server. The 2 server have already connection. The data of txt file have a thousand rows.

在同一个伺服器中汇入档案可以。

Importing a file in the same server is ok.

PHP:

if (($handle = fopen($directory_root."filename.csv", "r")) !== FALSE){
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){
        $sql = "INSERT INTO tablename(col1,col2,col3,col4,col5)
                VALUES ('".mysql_escape_string($data[0])."',
                        '".mysql_escape_string($data[1])."',
                        '".mysql_escape_string($data[2])."',
                        '".mysql_escape_string($data[3])."',
                        '".mysql_escape_string($data[4])."')";
        $query = mysql_query($sql);
    }
    fclose($handle);
}

$ch = curl_init('http://example.com/');
curl_setopt_array($ch, array(
    CURLOPT_POSTFIELDS => array(
        'files[]' => '@/var/www/html/files/',
    ),
));
if (false === ($res = curl_exec($ch))){
    die("Upload failed: " . curl_error($ch));
}


推荐答案

add curl_setopt($ ch,CURLOPT_POST,1);

'@ / var / www / html / files /',是一个目录...必须是文件

and '@/var/www/html/files/', is a directory ... must be file

这篇关于如何使用Curl将文件从另一个服务器上传到另一个服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆