//Get document Path
-(NSString *) Getdocumentpath
{
Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
return paths[0];
}
/**
* send picture
*/
-(void) Sendimage
{
path of the//sandbox document
NSString *documentpath = [self getdocumentpath];
//Picture sandbox path
nsstring *path = [NSString stringwithformat:@ "%@/1.png", documentpath];
NSData *data = [NSData Datawithcontentsoffile:path];
Afhttprequestoperationmanager *manager = [[Afhttprequestoperationmanager alloc]init];
manager.responseSerializer.acceptableContentTypes = [Nsset setwithobjects:@ "text/html", nil];
nsstring *url = [NSString stringwithformat:@ "%@/user/upload", Khttppath];
[Manager Post:url Parameters:nil constructingbodywithblock:^ (id<afmultipartformdata> formData) {
[FormData appendpartwithfiledata:data name:@ "test1" filename:@ "Test1.png" mimetype:@ "Image/png"];
} success:^ (afhttprequestoperation *operation, id responseobject) {
//NSLog (@ "YES%@", responseobject);
} failure:^ (Afhttprequestoperation *operation, Nserror *error) {
//NSLog (@ "Fail%@", error);
}];
}
PHP Interface
Public function upload () {
//Upload pictures
$config = Array (
' maxSize ' = * 1024x768,
' rootpath ' = './home/',//root directory
' savepath ' = ' images/post/',//Picture folder directory
' autosub ' = True,
' savename ' = = Array (' uniqid ', '),
' exts ' = = Array (' jpg ', ' gif ', ' PNG ', ' jpeg '),
' autosub ' = False,
' subname ' = Array (' Date ', ' YMD '),
);
$upload = new \think\upload ($config);//instantiation of upload class
$info = $upload-upload ();
if ($info) {
echo json_encode (Array (' code ' = +, ' data ' = $info));
}
Else
{
echo json_encode (Array (' Code ' = ' + ', ' data ' = $upload-GetError () ));
}
}
Ios-Pictures uploaded to the server