2011-03-16 30 views
2

我真的,真的,真的可以使用一些幫助文件的問題。我已經到處找一些詳細文檔(傻瓜)使用ASIFormDataRequest上載相片。有人能通過我在這裏的生活線嗎?新手具有上傳使用ASIHTTPRequest

這裏是(按照相關件)我有,雖然我知道我可能是遙遠。

Camera.h

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

... 

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]; 
} 

這裏是我接受它的腳本。

$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(); 

下面是結果我得到

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

) 

請幫助:(

回答

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); 

的圖像,並開始工作時,所拍攝圖像的高度和寬度將大於2000x2000更何況降低它,並給一個嘗試。

[request setData:imageData withFileName:@"photo.jpg" andContentType:@"image/jpeg" forKey:@"file"]; 

這是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!"; 
} 
+0

我給它,只要我能打出的感謝! – Mitchell

+1

你搖滾!!!只是讓其他人知道你 – Mitchell

+0

偉大[R!我工作得很好.... – user2136