[함수] 소켓으로 파일전송하기 정보
[함수] 소켓으로 파일전송하기
첨부파일
본문
/*
* 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
*/
* 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");
$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);
$client = new HttpClient($host);
if($cookie) $client->setCookies($cookie); // 쿠키가 있으면 쿠키를 설정한다.
$ret = $client->get($url);
// 결과 받기
$pageContents = $client->getContent();
$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")
);
$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);
$client = new HttpClient($host);
if($cookie) $client->setCookies($cookie);
$ret = $client->post($url, $post, $file); // 전송할 파일이 없는 경우 $client->post($url, $post);
// 결과 받기
$pageContents = $client->getContent();
$pageContents = $client->getContent();
echo "<xmp>$pageContents</xmp>";
────────────────────────────────────────
### 참고사항 ###
※ 포스트 데이터를 사용 안할때 : $post = Array();
※ 첨부 파일을 사용 안할때 : $file = 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")
);
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서버에 파일이 저장된 경로가 된다.
* path = A서버에서 B서버로 파일을 전송할때 A서버에 파일이 저장된 경로가 된다.
<FORM enctype="multipart/form-data" method="post">
<INPUT type=file name="file_1">
<INPUT type=file name="file_2">
</FORM>
<INPUT type=file name="file_1">
<INPUT type=file name="file_2">
</FORM>
--------------------------------------------------------------------------------
이상 입니다 ^^* 즐거운 하루 보내시구요~ 추천 꼭 눌러주세요 ~ ^^* 감사감사합니다.
추천
4
4
댓글 2개
어떻게 사용하는건지요?
네 추천이여