libcurl上传文件到服务器,使用php的libcurl注册用户并将文件上传到服务器

/*

options

*/

//the list url

$expUrl='http://hbcms/user/list_resource.php';

//the user info to be registered

$regUser='jiong';

$regPass='jiong';

$regMail='jiong@jiong.com';

$regUrl=str_replace('list_resource.php','register.php',$expUrl);

// options for image upload

$fileDir='@D:imgb.jpg';

$fileTitle='aaaaaaaaaaaaa';

$fileDesc='aaaaaaaaaaaaadesc';

$uploadImgUrl=str_replace('list_resource.php','add_resource.php',$expUrl);

/*

register function

*/

function reg($regurl,$u,$p,$m)

{

$ch = curl_init();

$options=array(

CURLOPT_URL=>$regurl,

CURLOPT_RETURNTRANSFER=>true,

CURLOPT_POST=>true,

CURLOPT_POSTFIELDS=>'mod=register_now&next_url=index.php&addon_app=&referrer_id=&login_name='.$u.'&login_pass='.$p.'&confirm_login_pass='.$p.'&login_email='.$m.'&nickname=&gender=0&qq=&mobile=&telephone=&true_name=&website_name=&website_url=&my_question=&my_answer=',

CURLOPT_COOKIESESSION=>true,

CURLOPT_HEADER=>true,

CURLOPT_COOKIEJAR=>'c:cookie.txt'

);

curl_setopt_array($ch,$options);

$data = curl_exec($ch);

if(strpos($data,'成功')){

printf("register ok :)n");

curl_close($ch);

return true;

}else{

printf("register failed:(n");

curl_close($ch);

return false;

}

}

/*

image uploading function

*/

function uploadImg($uploadimgurl,$filedir,$filetitle,$filedesc)

{

$ch = curl_init();

$options=array(

CURLOPT_COOKIEFILE=>'c:cookie.txt',

CURLOPT_URL=>$uploadimgurl,

CURLOPT_RETURNTRANSFER=>1,

CURLOPT_POST=>1,

CURLOPT_POSTFIELDS=>http_build_query(array(

'MAX_FILE_SIZE'=>'33554432',

'preview_area_id'=>'upload_file',

'editor_area_id'=>'body',

'js_function'=>'',

'resource_id'=>'',

'show_top_part'=>'no',

'file_1'=>$filedir,

'file_title_1'=>$filetitle,

'file_desc_1'=>$filedesc

))

);

curl_setopt_array($ch,$options);

$data = curl_exec($ch);

if(strpos($data,'注意')){

printf("upload ok :)n");

}else{

printf("upload failed :(n");

}

curl_close($ch);

}

if(reg($regUrl,$regUser,$regPass,$regMail) != false)

{

uploadImg($uploadImgUrl,$fileDir,$fileTitle,$fileDesc);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值