I have the url to a file on a remote server. The url is something like this: http://www.example.com/file/. As you can see, I don't have the file extension, but when I execute this url directly in a browser, a zip file is download. What I'm trying to do is not to downloaded the file, but upload it to a different location (on my machine or another server). How can I do this?
I tried getting the content of the file with file_get_contents like this:
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>array('X-Authentication: '.$_POST['access_token'], 'Content-Length: '.$_POST['file_size'])
)
);
$context = stream_context_create($opts);
$file = file_get_contents('http://www.example.com/file/', false, $context);
And then trying to send the file with cURL like this:
$post = array('extra_info' => $_POST['file_size'],'file_contents'=>'@'.$file);
$curl2 = curl_init();
curl_setopt_array($curl2, array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://localhost/manage_files/upload.php?action=do_upload',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $post
));
curl_exec($curl2);
But when I do this I get the following error:
failed to open stream: HTTP request failed!
Error: "couldn't open file "" " - Code: 26
Any idea how to achieve this? Don't forget I'm using PHP version 5.3
Thanks in advance.
PS : upload.php is the file where I would actually perform the upload (by calling move_uploaded_file and using $_FILES, etc...)