Reputation: 297
first , i am sorry for moderators for this more posts ,,
i have in my control panel , upload files page
but i want upload files on another server <- i have two servers
the first server control panel ( upload page ) url is
first_server.com/admin/upload.php
my second server link is
files.second_server.com
how i can upload files to the second server from the first server ?
without redirect to the second server
my first server content is - upload.php
<form -- action=i dont know what i should set in action>
<input name=myfile type=file>
<input type=submit>
</form>
the second server file is - proccess.php
if($_FILE['myfile']){
move_uploaded_file.......
//print the file link , to get it by my first page on first server
echo $second_server_full_path . '/' . $_FILE['myfile']['name'];
}
so .. how i can done this job via curl or file_get_content
i think file_get_content will be fine .. but the max timeout is too low !
Please help !
Upvotes: 0
Views: 1274
Reputation: 198198
how i can upload files to the second server from the first server ? without redirect to the second server
With redirection I assume you mean that the post request is sent to the second server.
At first, technically this is not possible. The form's data will be sent to the server specified, if by requirements you want to save the files on the second server, the second server needs to receive the data.
If you don't want to send the files to the second server via the browser, you need to send the files to the second server via the first server. For example you can create a network share in the second server and then in your submit script on the first server, you move over the files to the second server via the share.
For transferring files via curl (note: the @
in front of the file path):
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
"myfile"=>"@/path/to/myfile.jpg",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
Instead of using curl, Supported Protocols and Wrappers might be worth to look into, e.g. to just transfer the files over via FILE/FTP/SSH.
Upvotes: 2