繁体   English   中英

从iOS应用程序将文件上传到服务器

[英]Upload files to the server from iOS app

我可以将图像以外的文件上传到iOS应用程序上的服务器吗? 我使用UIImagePickerController,它可以选择图像或拍照,然后将它们附加并上传到服务器。 我可以用iPhone中的word或pdf文件做同样的事情吗,请帮帮我!

这是ASIHTTP库使用的代码,此处ASIHTTP库下载

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"Your Url"];

[request setPostValue:@"test" forKey:@"value1"];
[request setPostValue:@"test" forKey:@"value2"];

[request setTimeOutSeconds:20];

//Create a 256KB file
NSData *data = [[NSMutableData alloc] initWithLength:256*1024];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"file"];
[data writeToFile:path atomically:NO];

[request setFile:path forKey:@"file"];

[request startAsynchronous];

假设您使用的是PHP Server,那么下面的代码可能会对您有所帮助

$filedir = '';
$uploadfile = $filedir.basename($_FILES['myfile']['name']);


move_uploaded_file($_FILES['myfile']['tmp_name'], $uploadfile);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM