我创建了一个iOS应用程序,它使用 将相机拍摄的图像上传到服务器MKNetworkEngine
,如以下教程中所述新上传照片的路径。成功!
问题:我无法使用我自己的 PHP 代码来捕获该文件并将其保存在我的网络服务器上。我不明白posttestserver.com是如何成功获得它的,但我非常简单的 php 不是。
iOS端:
NSData *image = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 0.1);
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
@"woody", @"userName", @"testPassword", @"password", nil];
//WORKS:
self.flUploadEngine = [[fileUploadEngine alloc] initWithHostName:@"posttestserver.com" customHeaderFields:dic];
//Doesnt work:
self.flUploadEngine = [[fileUploadEngine alloc] initWithHostName:@"camerademander.com" customHeaderFields:dic];
NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"testApp", @"appID",
nil];
self.flOperation = [self.flUploadEngine postDataToServer:postParams path:@"/users/recieveStub3.php"];
[self.flOperation addData:image forKey:@"userfile" mimeType:@"image/jpg" fileName:@"upload.jpg"];
[self.flOperation addCompletionHandler:^(MKNetworkOperation* operation) {
NSLog(@"HTTP 200: success");
NSLog(@"%@", [operation responseString]);
}
errorHandler:^(MKNetworkOperation *errorOp, NSError* error) {
NSLog(@"%@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
[alert show];
}];
[self.flUploadEngine enqueueOperation:self.flOperation];
php:
echo "Connected to server successfully.";
$uploaddir = '/photos/';
$file = basename($_FILES['userfile']['upload.jpg']);
$uploadfile = $uploaddir . $file;
if (move_uploaded_file($_FILES['userfile']['upload.jpg'], $uploadfile)) {
echo "Successfully uploaded! :{$file}:";
}
这阻止了我的项目向前发展——我不明白 posttestserver 是如何获得结果的,但我不是,尤其是当我能够成功连接到我自己的 php 和服务器时。
提前非常感谢!