0

次のチュートリアルで概説するようにMKNetworkEngine、カメラで撮影した画像を を使用してサーバーにアップロードする iOS アプリケーションを作成しました 。ホストをposttestserver.comに設定すると、名前が示すようにパブリック POST テスト サーバーで、URL が返され、新しくアップロードされた写真へのパス。成功!

問題:独自の PHP コードを使用してそのファイルをキャプチャし、Web サーバーに保存することができません。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とサーバーに正常に接続できる場合はわかりません。

よろしくお願いします!

4

2 に答える 2

0

それはサーバーのアクセス許可の問題であることが判明しました-私はecho $file, is_writable($file) ? ' is writable' : ' is NOT readable', "\n";これを特定するために使用しました。

于 2013-11-24T13:11:53.807 に答える