您好,欢迎访问一九零五行业门户网

ios ASIFormDataRequest上传图片到php服务器

需要 asihttprequest第三方库的童鞋请到我的资源下载 使用asihttprequest第三方库需要导入系统包如下: libz.1.2.5.dylib , mobilecoreservices.framework , systemconfiguration.framework , cfnetwork.framework , coregraphics.framework 需要导入 asihtt
需要asihttprequest第三方库的童鞋请到我的资源下载
使用asihttprequest第三方库需要导入系统包如下:
libz.1.2.5.dylib ,
mobilecoreservices.framework ,
systemconfiguration.framework ,
cfnetwork.framework  ,
coregraphics.framework
需要导入asihttprequest包里的asiformdatarequest.h
#import asiformdatarequest.h
//上传图片
-(void)uploadimages:(uibutton *)sender
{
    nsdata *data =uiimagepngrepresentation(self.img.image);
    nsurl *url = [[nsurlalloc]initwithstring:@http://127.0.0.1/uploadfile/upload.php];
    //以表格形式的请求对象
    asiformdatarequest *request = [[asiformdatarequestalloc]initwithurl:url];
    request.delegate =self;
    request.requestmethod =@post;//设置请求方式
    //添加请求内容
    [request adddata:datawithfilename:[nsstringstringwithformat:@%d.png,arc4random()]andcontenttype:@image/pngforkey:@file];
    //开始异步请求
    [request startasynchronous];
//如果成功则自动执行
    [requestsetdidfinishselector:@selector(requestedsuccessfully)];
    //如果失败则自动执行
    [requestsetdidfailselector:@selector(requestedfail)];
}
-(void)requestedsuccessfully
{
   uialertview *alert = [[uialertviewalloc]initwithtitle:@提示message:@图片上传成功! delegate:nilcancelbuttontitle:@确定 otherbuttontitles:nil];
    [alertshow];
}
-(void)requestedfail
{
   uialertview *alert = [[uialertviewalloc]initwithtitle:@提示message:@图片上传失败! delegate:nilcancelbuttontitle:@确定 otherbuttontitles:nil];
    [alertshow];
}
使用的php文件 upload.php
其它类似信息

推荐信息