gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:10:32 26 4
gpt4 key购买 nike

我真的、真的、真的需要一些帮助。我到处查看了一些关于使用 ASIFormDataRequest 进行照片上传的详细文档(对于傻瓜)。有人可以通过我这里的生命线吗?

这是我所拥有的(相关的部分),尽管我知道我可能离题太远了。

相机.h

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

...

相机.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
)

)

请帮忙:(

最佳答案

我遇到了类似的问题,我使用

重新调整了图像的大小
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!";
}

关于php - 新手在使用 ASIHTTPRequest 上传文件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5319823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com