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


$ch = curl_init();

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

curl_setopt($ch, CURLOPT_URL, '');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);


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...)

$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.