1

这是我将图像上传到 php 服务器的代码,但图像在服务器上作为损坏的图像上传。下面是我的代码,请告诉我问题..我已经尝试使用可可休息客户端,图像正在从中正确上传。

    NSString *filename = @"connect-blue.png";
    UIImage *image = [UIImage imageNamed:filename];
    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 *postbody = [NSMutableData data];
    [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"profile_image\"; filename=\"%@\"\r\n",filename] dataUsingEncoding:NSUTF8StringEncoding]];
   [postbody appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];

    [postbody appendData:[postString dataUsingEncoding:NSUTF8StringEncoding]];
    NSData *imagedata = UIImageJPEGRepresentation(image,1.0f);

    [postbody appendData:[NSData dataWithData:imagedata]];
    [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary]  dataUsingEncoding:NSUTF8StringEncoding]];

php代码在这里

if(!empty($_FILES)){
//
  $imgname=$_FILES['image']['name'];
         $a=pathinfo($imgname);

  if(!empty($a['extension'])){  
   $img_name=$a['filename'];
   $img_ext=$a['extension'];
 }

  else

  {

    $img_name='';

   $img_ext='';

   }

   $img_pre=mktime();

   $image1=$img_pre."_".$imgname;
  move_uploaded_file($_FILES['image']['tmp_name'],  "uploads/images/" .  $image1);
4

2 回答 2

2

我找到了解决方案图片上传

于 2012-12-06T12:13:01.260 回答
0

您可以管理这两种技术的图像框架我的意思是当您从 iphone 发送图像时,图像的大小在 php 中仍然相同我认为您管理 Async Image 类

于 2012-12-05T10:50:42.640 回答