Upload file with php to another php server
Get the solution ↓↓↓Solution:
You can use CURL for this. Something like this should do it.
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@/path/to/file.txt'));
curl_setopt($ch, CURLOPT_URL, 'http://server2/upload.php');
curl_exec($ch);
curl_close($ch);
You can then handle the the server2 part as a regular file upload. See for more information on those options.
Answer
Solution:
You could use SOAP to send the file from one server to the other.
Receiving server:
<?php
$server = new Soap_Server( null, array('uri'=>'somerui') );
$server->addFunction( 'receiveFile' );
function receiveFile( $file ) {
file_put_contents( 'somepath', base64_decode( $file ) );
}
?>
Sending server:
<?php
$client = new Soap_Client( null, array('uri'=>'somerui') );
$client->receiveFile( base64_encode( file_get_contents( 'somepath' ) );
?>
Answer
Solution:
You need two Scripts.
First script that will in way emulate browser behavior, it will take a file and send it to seconds script, that will handles it just like regular file upload script.
My guess you have to use "http_post_fields" for the first script, it seems to handle files. http://us2.php.net/manual/en/function.http-post-fields.php
Good Luck.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: attempt to read property "id" on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.