PHP Upload File interface:
//Save Picture$json _result[' status '] = 0;$path= ' Upfile ';$json _result[' status '] = 0;$json _result[' successmsg '] = ' upload failed ';if(isset($_files[' Image '] )) { $upfile= ' upfile/'.$_files[' Image '] [' Name ']; if(! @file_exists($path )) { @mkdir($path ); } $result= @Move_uploaded_file($_files[' Image '] [' Tmp_name '],$upfile ); if(!$result) { $json _result[' status '] = 0; $json _result[' successmsg '] = ' upload failed '; $json _result[' datas '] =Array(' Savepath ' =$upfile ); Exit(Json_encode ($json _result ) ); }}$json _result[' status '] = 1;$json _result[' datas '] =Array(' savepath ' = '/'/'/'.$_server[' server_name ']. ":".$_server[' Server_port ']. " /".$upfile );Print_r(Json_encode ($json _result));iOS uploads images via the interface:
//Upload Avatar- (void) Uploaduserheadimage: (UIImage *) Image {//Get network managerAfhttpsessionmanager *manager =[Afhttpsessionmanager Manager]; //Set Request ParametersNsmutabledictionary *params=[Nsmutabledictionary dictionary]; [Manager POST:@"http://localhost:8888/upload_image.php"Parametersparamsconstructingbodywithblock:^ (ID<AFMultipartFormData>_nonnull FormData) { //Get Picture DataNSData *filedata = uiimagejpegrepresentation (image,1.0); //set the name of the uploaded imageNSDateFormatter *formatter =[[NSDateFormatter alloc] init]; Formatter.dateformat=@"YYYYMMDDHHMMSS"; NSString*str =[Formatter stringfromdate:[nsdate Date]]; NSString*filename = [NSString stringWithFormat:@"%@.png", str]; [FormData appendpartwithfiledata:filedata Name:@"Image"Filename:filename MimeType:@"Image/png"]; } Progress:^ (Nsprogress *_nonnull uploadprogress) {NSLog (@"%@", uploadprogress); } Success:^ (Nsurlsessiondatatask * _nonnull task,ID_nullable Responseobject) { //return ResultsNSLog (@"%@", responseobject[@"datas"]); } Failure:^ (Nsurlsessiondatatask * _nullable task, Nserror *_nonnull Error) {NSLog (@"%@", error); }];}
PHP--Upload file interface Authoring and IOS--end upload image AF Implementation