Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apple photopicker将用php拍摄的照片上传到mysql数据库_Php_Mysql_Xcode_Camera - Fatal编程技术网

Apple photopicker将用php拍摄的照片上传到mysql数据库

Apple photopicker将用php拍摄的照片上传到mysql数据库,php,mysql,xcode,camera,Php,Mysql,Xcode,Camera,我已经从苹果下载了photopicker的示例代码: 我修改了代码中表示MyViewController.m中拍摄的照片(快照按钮)结果的部分: // as a delegate we are being told a picture was taken - (void)didTakePicture:(UIImage *)picture { [self.capturedImages addObject:picture]; } 然后使用类似于此的代码将其推送到我的web服务器: NSDa

我已经从苹果下载了photopicker的示例代码:

我修改了代码中表示MyViewController.m中拍摄的照片(快照按钮)结果的部分:

// as a delegate we are being told a picture was taken
- (void)didTakePicture:(UIImage *)picture
{
    [self.capturedImages addObject:picture];
}
然后使用类似于此的代码将其推送到我的web服务器:

NSData *imageData = UIImageJPEGRepresentation(**_capturedImages.images**, 90);
NSString *urlString = @"http://localhost/upload.php";

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(returnString);
我的问题是,我一直有消息说文件无法上传或代码崩溃

我认为这只是一个正确访问结果图像并正确推送它的问题

因为我不知道如何从MyViewController.m中提取此图像:

@property (nonatomic, retain) **NSMutableArray** *capturedImages;
upload.PHP的PHP代码是:

<?php

    $file = basename($_FILES['userfile']['name']);
    $uploadFile = $file;
    $randomNumber = rand(0, 99999); 
    $newName = $randomNumber . $uploadFile;

    echo $file;

    echo $uploadFile;

    echo $randomNumber;

    echo $newName;

    if (is_uploaded_file($_FILES['userfile']['tmp_name'])) 
    {
        echo "Temp file uploaded. \r\n";
    } 
    else 
    {
        echo "Temp file not uploaded. \r\n";
    }

    if ($_FILES['userfile']['size']> 300000) {
        exit("Your file is too large."); 
    }

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) 
    {
            $postsize = ini_get('post_max_size');   //Not necessary, I was using these
            $canupload = ini_get('file_uploads');    //server variables to see what was 
            $tempdir = ini_get('upload_tmp_dir');   //going wrong.
            $maxsize = ini_get('upload_max_filesize');

            echo "http://localhost/{$file}" . "\r\n" . $_FILES['userfile']['size'] . "\r\n" . $_FILES['userfile']['type'] ;
    }

?>

谢谢


Regis

这是一个使用AFNetworking上传的好例子