2013-05-31 3 views
-2

파일을 읽고 다른 컴퓨터에서 수신 할 수 있도록 데이터를 게시하는 스크립트를 만들어야합니다.파일 보내기/받기 PHP 스크립트

어디에서 시작할 수 있습니까? 비슷한 것으로 보이는 PHP.Net의 유일한 것 dir("/etc/php5

답변

1

PHP를 사용하면 libcurl을 사용하여 파일을 원격 서버에 업로드 할 수 있습니다. 파일을 읽으려면 특별한 작업을 수행 할 필요가 없습니다. 단지 말리지 않도록하십시오. 여기에 파일을 전송하는 예입니다

$target_url = 'http://127.0.0.1/accept.php'; 
//This needs to be the full path to the file you want to send. 
$file_name_with_full_path = realpath('./sample.jpeg'); 
/* curl will accept an array here too. 
* Many examples I found showed a url-encoded string instead. 
* Take note that the 'key' in the array will be the key that shows up in the 
* $_FILES array of the accept script. and the at sign '@' is required before the 
* file name. 
*/ 
$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$target_url); 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$result=curl_exec ($ch); 
curl_close ($ch); 
echo $result; 

이 코드는 모든 세부 사항에 대한 http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/를 참조 Derak에서입니다.

you can simply use curl from the command line 또는 셸 스크립트를 사용하여 PHP에이 작업을 수행 할 필요가 없습니다.

+0

링크가 작동하지 않습니다. 게이트웨이 오류입니다. 답변에 세부 사항을 게시 할 수 있습니까? – gibberish

+0

링크는 나에게 도움이되지만 더 자세한 정보로 답변을 업데이트했습니다. – nullability

+0

링크는 지금 나를 위해 일하지만, 코드를 게시 해 주셔서 감사합니다. 향후 독자가 사이트에 다시 문제가있을 때 가장 좋습니다. – gibberish

0

XML PHP 함수를 사용하여 데이터를 덤프 파일로 구문 분석 한 다음 다른 컴퓨터에서 다른 함수로 읽습니다.