afnetworking 上传 php,php – AFNetworking上传图像

我看了几个例子,但我认为我的问题可能在

PHP中.我正在尝试使用AFNetworking从iPhone上传图像到服务器.这是我的对象代码:

-(IBAction)uploadButtonClicked:(id)sender

{

NSData *imageToUpload = UIImageJPEGRepresentation(mainImageView.image, 90);

AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://www.THESERVER.com"]];

NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"/PROJECT/upload.php" parameters:nil constructingBodyWithBlock: ^(id formData) {

[formData appendPartWithFileData: imageToUpload name:@"file" fileName:@"temp.jpeg" mimeType:@"image/jpeg"];

}];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

NSString *response = [operation responseString];

NSLog(@"response: [%@]",response);

[MBProgressHUD hideHUDForView:self.view animated:YES];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

[MBProgressHUD hideHUDForView:self.view animated:YES];

if([operation.response statusCode] == 403){

NSLog(@"Upload Failed");

return;

}

NSLog(@"error: %@", [operation error]);

}];

[operation start];

}

这是我的upload.php:

function upload(){

$uploaddir = '/uploads/';

$file = basename($_FILES['file']['name']);

$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {

sendResponse(200, 'Upload Successful');

return true;

}

sendResponse(403, 'Upload Failed');

return false;

}

当我尝试上传它失败

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {

并返回我设置的403 / false状态代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值