PHP--Upload file interface Authoring and IOS--end upload image AF Implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.