新手在使用ASIHTTPRequest上传文件时遇到问题

Mit*_*ell 2 php iphone cocoa-touch file-upload ios

我真的可以真正地使用一些帮助.关于使用ASIFormDataRequest进行照片上传,我已经查看了一些详细的文档(对于傻瓜).有人能通过我这里的生命线吗?

这是我所拥有的(相关部分)虽然我知道我可能会离开.

Camera.h

#import <UIKit/UIKit.h>
@class ASIFormDataRequest; 

...
Run Code Online (Sandbox Code Playgroud)

Camera.m

#import "Camera.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"

...

- (void)uploadImage:(NSData *)imageData filename:(NSString *)filename{
NSURL *url = [NSURL URLWithString:@"http://moosesightings.com/test.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
// Upload a file on disk
[request setData:imageData withFileName:filename andContentType:@"image/jpeg" forKey:@"userfile"];
[request setDelegate:self];
[request startAsynchronous];
}

...

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSString *imageName = @"uploaded.jpg";

// Save image
//UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
[self uploadImage:UIImageJPEGRepresentation(imageView.image, 1.0) filename:imageName];

captionControls.hidden = NO;
[textView becomeFirstResponder];

[picker release];
}
Run Code Online (Sandbox Code Playgroud)

这是我收到的脚本.

$dir_dest = 'uploads/';
ob_start();
print_r($_FILES);
$test = ob_get_contents();
ob_end_clean();
$db->insert('connecttest', array('ts'=>date('Y-m-d H:i:s'), 'tempfield'=>$test))->execute();
Run Code Online (Sandbox Code Playgroud)

这是我得到的结果

Array
(
    [(null)] => Array
        (
            [name] => (null)
            [type] => (null)
            [tmp_name] => C:\Windows\Temp\phpCFF0.tmp
            [error] => 0
            [size] => 0
        )

)
Run Code Online (Sandbox Code Playgroud)

请帮忙 :(

pra*_*epa 7

我遇到了类似的问题,我使用了重新调整图像的大小

UIImage *im = [info objectForKey:@"UIImagePickerControllerOriginalImage"] ;
UIGraphicsBeginImageContext(CGSizeMake(320,480)); 
[im drawInRect:CGRectMake(0, 0,320,480)];
newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();
NSData* imageData=UIImageJPEGRepresentation(newImage, 0.5); 
Run Code Online (Sandbox Code Playgroud)

并且它开始工作,捕获的图像的高度和宽度将超过2000x2000所以减少它并尝试.

[request setData:imageData withFileName:@"photo.jpg" andContentType:@"image/jpeg" forKey:@"file"];
Run Code Online (Sandbox Code Playgroud)

这是php脚本.

$filename="uploaded";
$target_path = "uploads/";
$target_path = $target_path .$filename.".jpg"; 
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
echo "uploaded an image";
} else{
    echo "There was an error uploading the file, please try again!";
}
Run Code Online (Sandbox Code Playgroud)