curlフォームのパッケージ
最近、プロジェクトの責任者はインタフェースを調整するにはcurlを使わなければならないと要求しました.
<?php
/**
* Copyright (c) 2008, ***
* All rights reserved.
*
* :
* :
* :1.0
* @author ***
* @since 09.01.08 01:00:14
*/
/**
* class CCurl
*/
class CCurl {
protected
$url="",
$postfields=array();
private
$hd=null,
$options = array(),
$timeout = 5;
/**
* CCurl
* @param
*/
public function __construct($url="") {
$this->initialize($url);
}
public function __destruct(){
curl_close($this->hd);
}
/**
* function
* @ps
* @param $url:str url
* @return
*/
public function initialize($url)
{
$this->url = $url;
if($url)
$this->hd = curl_init($url);
else
$this->hd = curl_init();
}
/**
* function url
* @ps
* @param
* @return
*/
public function setUrl($url)
{
self::setOption(CURLOPT_URL,$url);
}
/**
* function set option
* @ps
* @param $optk:option curl option
* @param $optv:mixed
* @return Boolean
*/
public function setOption($optk,$optv)
{
$this->options[$optk] = $optv;
}
/**
* function
* @ps
* @param
* @return
*/
public function setFile($fieldname ,$file)
{
$this->postfields[$fieldname] = "@$file";
}
/**
* function post
* @ps
* @param
* @return
*/
public function setPost($fieldname ,$post)
{
$this->postfields[$fieldname] = $post;
}
/**
* function get
* @ps
* @param
* @return
*/
public function getResult()
{
$this->options[CURLOPT_RETURNTRANSFER] = true;
$this->options[CURLOPT_TIMEOUT] = $this->timeout;
if($this->postfields)
{
self::setOption(CURLOPT_POST,true);
self::setOption(CURLOPT_POSTFIELDS,$this->postfields);
}
curl_setopt_array($this->hd, $this->options);
return curl_exec($this->hd);
}
}
$test = new CCurl("localhost/test.php?dede=asdf");
$test->setUrl("localhost/test.php?dede=1111");
$test->setFile("dll","c:/gdiplus.dll");
$test->setPost("test","asdf");
echo $test->getResult();
?>