2012-07-04 3 views
0

POST 메서드를 통해 내 서버에서 다른 서버로 파일을 보내는 스크립트를 만들려고합니다. html로는 다음과 같이 보일 수 있습니다 :이 부분자동으로 웹 서버에서 파일 게시

<form action="https://anotherserver/receive.php" method="POST" enctype="multipart/form-data"> 
    <input type="file" name="file" /> 
    <input type="submit" /> 
</form> 

, 내가 다른 서버로 내 컴퓨터에서 파일을 보낼 수 있습니다. 그러나 조건이 사실이라면 스크립트는 내 웹 서버에서 파일을 보내야합니다. 예를 들어, 내 웹 사이트에서 파일을 만들고 "OK"를 누르면 파일이 자동으로 외부 웹 서버로 전송됩니다. 그런 방법이 가능할까요? 어떤 도움이라도 대단히 감사합니다.

답변

2

이 코드는 다른 서버에 파일을 게시 할 예정입니다 : http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html

+0

감사합니다 :

<?php $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_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($ch, CURLOPT_URL, 'https://anotherserver/receive.php'); curl_setopt($ch, CURLOPT_POST, true); $post = array( "file"=>"/path/to/myfile.jpg", ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $response = curl_exec($ch); ?> 

는 각색! 그것이 내가 필요한 것입니다. – Cosmi

관련 문제