我正在开发一个适用于iOS的社交网络应用程序并拥有一个mySQL数据库,我已经在php中编写了一个Web服务。我有一切工作(创建帐户/登录),但我不知道如何从服务器上传或下载图像。当用户创建帐户时,我通过
在服务器上为该用户图像创建一个文件夹<?php
mkdir("members/$id", 0755);
?>
在应用程序端,我正在上传像这样的图像
NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/edit_profile.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"smiley1.jpg"]);
[request setPostValue:imageData forKey:@"pic"];
[request setDelegate:self];
request startAsynchronous];
然后在edit_profile.php
if (isset($_POST["pic"])){
//Not sure what to do here
//I've done this from a website before via:
/*
$newname = "image01.jpg";
$place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "members/$id/".$newname);
$success_msg = "Image uploaded succcessfully!";
*/
}