php - AFNetworking Uploading Image -
i've @ few examples think problem may in php. trying upload image server iphone using afnetworking. here obj-c code:
-(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 <afmultipartformdata>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]; } this 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; } when try upload fails @
if (move_uploaded_file($_files['file']['tmp_name'], $uploadfile)) { and returns 403 / false status code set
it silly mistake...
in php needed
$uploaddir = 'uploads/'; instead of
$uploaddir = '/uploads/';
Comments
Post a Comment