gpt4 book ai didi

php - 将照片从iPhone上传到Web服务器

转载 作者:行者123 更新时间:2023-12-01 16:57:40 25 4
gpt4 key购买 nike

我尝试通过使用许多不同的.php上传脚本将照片从iPhone应用程序上传到webserver,但到目前为止我还没有成功!

请检查我的iPhone源代码:

- (IBAction)upload:(id)sender {
NSData *imageData = UIImageJPEGRepresentation(imageView.image, 90);
NSString *urlString = @"http://wasnaga.nestons.org/420/upload.php";

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *boundary = [NSString stringWithString:@"------------------------1473780983146499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"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]];
[request setHTTPBody:body];

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString =[[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(returnString);
}

有什么错误吗?您可以帮我处理.php文件吗?

最佳答案

看起来您在第一个appendData行中缺少反斜杠:

@"\r\n--%@r\n"

它应该是:
@"\r\n--%@\r\n"

关于php - 将照片从iPhone上传到Web服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10260318/

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