How to upload a file from another server to another server using Curl in Shell script and PHP?
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);
and
'@/var/www/html/files/',
is a directory ... must be file