如何使用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