0

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 !

Osama Tarek
  • 297
  • 5
  • 16
  • How do you know the max timeout is too low if you haven't even tried the file upload relaying yet? Also in case that's really the case, *you* will have to adapt those server settings. We can't. – mario Aug 15 '11 at 07:13
  • possible duplicate of [How to send upload file to other website by using curl in php?](http://stackoverflow.com/questions/3706311/how-to-send-upload-file-to-other-website-by-using-curl-in-php) – mario Aug 15 '11 at 07:17
  • first replay : 30 mins ago , second replay 27 mins .. 30 minutes from your time to close this post ! it's high price .. anyway thank you – Osama Tarek Aug 15 '11 at 07:44
  • ^^ for your information .. the max timeout for file_get_content -> 30 seconds ! – Osama Tarek Aug 15 '11 at 07:46

1 Answers1

2

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • More specific @hakre meant share to make use of something like http://php.net/manual/en/book.ftp.php – Hari K T Aug 15 '11 at 07:20