Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.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
使用PHP&;将imagedata从XCode插入MySQL数据库;JSON_Php_Iphone_Xcode_Iphone Sdk 3.0 - Fatal编程技术网

使用PHP&;将imagedata从XCode插入MySQL数据库;JSON

使用PHP&;将imagedata从XCode插入MySQL数据库;JSON,php,iphone,xcode,iphone-sdk-3.0,Php,Iphone,Xcode,Iphone Sdk 3.0,如何使用JSON从XCode通过PHP在MySQL数据库中插入/存储图像?从XCode,您可以: -(void) uploadImage: (UIImage *)image { NSData *imageData = UIImageJPEGRepresentation(image, 10); // setting up the URL to post to NSString *urlString = @"http://url.of

如何使用JSON从XCode通过PHP在MySQL数据库中插入/存储图像?

从XCode,您可以:

-(void) uploadImage: (UIImage *)image 
{
                NSData *imageData = UIImageJPEGRepresentation(image, 10);
        // setting up the URL to post to
        NSString *urlString = @"http://url.of.your.server/imagesupload.php";

        // setting up the request object now
        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
        [request setURL:[NSURL URLWithString:urlString]];
        [request setHTTPMethod:@"POST"];

        /*
         add some header info now
         we always need a boundary when we post a file
         also we need to set the content type

         You might want to generate a random boundary.. this is just the same
         as my output from wireshark on a valid html post
         */
        NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
        NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
        [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

        /*
         now lets create the body of the post
         */
        NSMutableData *body = [NSMutableData data];
        [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"imagename.jpg\"\r\n",index] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[[NSString stringWithString:@"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]];
        // setting the body of the post to the reqeust
        [request setHTTPBody:body];

        // now lets make the connection to the web
        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

        NSLog(returnString);
}
在PHP中,您可以执行以下操作:

function imageUpload()
{
// Make sure the user actually 
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

      // Temporary file name stored on the server
      $tmpName  = $_FILES['image']['tmp_name'];  

      // Read the file 
      $fp      = fopen($tmpName, 'r');
      $data = fread($fp, filesize($tmpName));
      $data = addslashes($data);
      fclose($fp);


      // Create the query and insert
      // into our database.
      $query = "INSERT INTO tbl_images ";
      $query .= "(image) VALUES ('$data')";
      $results = mysql_query($query, $link);

      // Print results
      print "Thank you, your file has been uploaded.";

}
else {
   print "No image selected/uploaded";
}

// Close our MySQL Link
mysql_close($link);
}

在xcode从Uiimageview获取imagedata中,我想将此图像保存在mysql中,以便通过Json解析器使用PHP.help me20954字节。我通过xcode中的PHP将员工详细信息存储在服务器上,除了图像之外,所有详细信息都存储在mysql中。我想保存员工形象。如何通过NsUrl将imagedata发送到PHP以及将图像插入mysql数据库的PHP代码?帮助我..如何将图像作为blob数据类型插入mysql数据库。如何通过json将图像从xcode发送到insert。有人可以发送php脚本吗?帮帮我…谢谢