将图像上传到远程服务器,iPhone [英] Uploading images to Remote Server, iPhone

查看:113
本文介绍了将图像上传到远程服务器,iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图书馆或照相机中获取图像,然后将其上传到远程服务器,然后我可以在其中检索每个上传图像的URL.

I would like to take images from library, or camera and upload them to a remote server, where I could then retreieve a URL for each image uploaded.

我希望从头开始.并且正在寻找从何处开始的帮助.

Im looking to get started from scratch. And am looking for some help on where to start.

我需要用最简单的方法做到这一点,即php和mysql. 我应该从哪里开始?!

Im need to do this the simplest way, php and mysql. Where should I start?!

此外,我宁愿不使用任何第三方.

Also, I rather not use any third partys for this.

很简单,

我如何连接数据库, 插入 读 完成!

How do i DB connect, Insert Read Done!

让我知道.

推荐答案

哇,我很摇滚!

还有这个家伙. http://iphone.zcentric.com /2008/08/29/post-a-uiimage-to-the-web/

这里是我实现的

UIImage *myImage = [UIImage imageNamed:@"foo.png"];
NSData *imageData = UIImagePNGRepresentation(myImage);
// setting up the URL to post to
NSString *urlString = @"myurl/insert.php";

// setting up the request object now
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"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 stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile.jpg\"\r\n"] 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来说,它看起来像.

As for the PHP it looks like.

   <?php
       $uploaddir = './uploads/';
   $file = basename($_FILES['userfile']['name']);
   $uploadfile = $uploaddir . $file;

  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        echo "myurl/uploads/{$file}";
      } 
?>

老板!!! @lessfame

Boss!!! @lessfame

这篇关于将图像上传到远程服务器,iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆