Ios-Pictures uploaded to the server

Source: Internet
Author: User



//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

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.