Lion King
Lion King

Reputation: 33813

Send data from server to another by curl or any other way

I have two servers. The first (Local) is the server which has the script.
The second (Remote) is the server which has uploaded files only (just for storage).

Now I'm confused about how to upload the files, and I have 2 ways and I don't know what the best one of them.

The ways:

  1. Upload the file to the local server first and make all security operations like (check file size,file type, and so on), then upload again to the second server (remote server).

  2. Upload the file to the second server (remote server) directly, and make all checks and security operations in there, then send the file information to the first server (local) to store the info into database.

  3. Or there is another way is better than them ?

I have tried to apply the second way, by send the file directly to the second server (remote server) and then after everything is ok, the second server (remote server) send to the first server (local) all information about the uploaded file by curl.

For example:
The following code written in file exists in php file in the second server (remote server).

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localServer/script/receiveReques.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_POST, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('fileName' => 'filename.zip', 'size' => 1000, 'path'=> 'http://remoteserver.com/files/filenmae.zip'));
curl_exec($ch);
curl_close($ch);

But the problem I don't know how to get the sent information.

The summary of my questions is:

  1. What the best way to do that ?
  2. How to receive the file information from the second server (remote server) that has been sent by curl ?

Upvotes: 1

Views: 2303

Answers (1)

exussum
exussum

Reputation: 18550

you have

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

all you need to do is use the data it returns

$data = curl_exec($ch);

all of the data is now in $data

Upvotes: 3

Related Questions