[함수] 소켓으로 파일전송하기 > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

[함수] 소켓으로 파일전송하기 정보

[함수] 소켓으로 파일전송하기

첨부파일

HttpClient.zip (3.7K) 32회 다운로드 2011-11-24 10:33:10

본문

/*
 * Diese Version des HttpClients wurde von Sven Wappler erstellt. Sie basiert auf
 * HttpClient 0.9 von Simon Willison (http://simon.incutio.com)
 * http://www.wappler.eu/wp-content/uploads/files/HttpClient.class.phps (Original Sorce Link)
 * Last Modify by kalsome Baesang 07/26/2011
 */
 
───────────────────────────────────────
 
### 간단 예제 ###
// 변수 설정
$host = "www.google.com";
$url = "/test/get.php?a=100";
$cookie = array("b"=>"200","c"=>"300");
 
// 함수 호출
$client = new HttpClient($host);
if($cookie) $client->setCookies($cookie); // 쿠키가 있으면 쿠키를 설정한다.
$ret = $client->get($url);
 
// 결과 받기
$pageContents = $client->getContent();
echo "<xmp>$pageContents</xmp>";
 
────────────────────────────────────────
 
### 첨부파일 예제 ###
 
// 변수 셋팅
$host = "www.google.com";
$url = "/test/upload.php?a=100";
$post = array('p1'=>'Hello', 'p2'=>'World');
$cookie = array('c1'=>'1234', 'c2'=>'5678');
$file = array(
array("name"=>"file_1", "path"=>"/var/www/html/upload/a.jpg"),
array("name"=>"file_2", "path"=>"/var/www/html/upload/b.jpg")
);
 
// 함수 호출
$client = new HttpClient($host);
if($cookie) $client->setCookies($cookie);
$ret = $client->post($url, $post, $file); // 전송할 파일이 없는 경우 $client->post($url, $post);
 
// 결과 받기
$pageContents = $client->getContent();
echo "<xmp>$pageContents</xmp>";
 
────────────────────────────────────────
 
### 참고사항 ###
※ 포스트 데이터를 사용 안할때 : $post = Array();
※ 첨부 파일을 사용 안할때 : $file = Array();
※ 첨부파일은 아래와 같이 생각하면 된다.
$file = array(
array("name"=>"file_1", "path"=>"/var/www/html/data/play.jpg"),
array("name"=>"file_2", "path"=>"/var/www/html/data/boy.jpg")
);
* name = INPUT 필드의 name이 된다.
* path = A서버에서 B서버로 파일을 전송할때 A서버에 파일이 저장된 경로가 된다.
<FORM enctype="multipart/form-data" method="post">
<INPUT type=file name="file_1">
<INPUT type=file name="file_2">
</FORM>
 
 
--------------------------------------------------------------------------------
 
이상 입니다 ^^* 즐거운 하루 보내시구요~ 추천 눌러주세요 ~ ^^* 감사감사합니다.
추천
4
  • 복사

댓글 2개

© SIRSOFT
현재 페이지 제일 처음으로