Hi,
I want to upload files from one remote server to another using CURL

I used following to upload a text file in "localhost/uploads/example.txt" to another machine http://192.168.0.202/example/

<?php


$ch = curl_init();

$data = array('name' => 'Foo', 'file' => '@localhost/uploads/example.txt');

curl_setopt($ch, CURLOPT_URL, 'http://192.168.0.202/example/');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?>

The code is not working.

Recommended Answers

All 5 Replies

The difference between your code and the one on php.net is that that one uses an absolute file path.

please suggest any sample script.

i don't think you have permissions to do that on remote.. :S but you can try file_get_contents (i guess it will do the same, but...)

<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.