For shoes requiring a third-party library of ASIHTTPRequest, please download my resources. To use the third-party library of ASIHTTPRequest, You need to import the system package as follows: libz.1.2.5.dylib, MobileCoreServices. framework, SystemConfiguration. framework, CFNetwork. framework, CoreGraphics. framework needs to import ASIHTT
For shoes requiring a third-party library of ASIHTTPRequest, please download my resources. To use the third-party library of ASIHTTPRequest, You need to import the system package as follows: libz.1.2.5.dylib, MobileCoreServices. framework, SystemConfiguration. framework, CFNetwork. framework, CoreGraphics. framework needs to import ASIHTT
For shoes that require a third-party ASIHTTPRequest library, please download them from my resources.
To use the ASIHTTPRequest third-party library, you need to import the system package as follows:
Libz.1.2.5.dylib,
MobileCoreServices. framework,
SystemConfiguration. framework,
CFNetwork. framework,
CoreGraphics. framework
Import ASIFormDataRequest. h In the ASIHTTPRequest package
# Import "ASIFormDataRequest. h"
// Upload an image
-(Void) uploadImages :( UIButton *) sender
{
NSData * data = UIImagePNGRepresentation (self. img. image );
NSURL * url = [[NSURLalloc] initWithString: @ "http: // 127.0.0.1/uploadFile/upload. php"];
// Request object in table form
ASIFormDataRequest * request = [[ASIFormDataRequestalloc] initWithURL: url];
Request. delegate = self;
Request. requestMethod = @ "POST"; // you can specify the request method.
// Add request content
[Request addData: datawithFileName: [NSStringstringWithFormat: @ "mongod.png", arc4random ()] andContentType: @ "image/png" forKey: @ "file"];
// Start asynchronous request
[Request startAsynchronous];
// If successful, the task is automatically executed.
[RequestsetDidFinishSelector: @ selector (requestedSuccessfully)];
// Automatically execute the command if it fails.
[RequestsetDidFailSelector: @ selector (requestedFail)];
}
-(Void) requestedSuccessfully
{
UIAlertView * alert = [[UIAlertViewalloc] initWithTitle: @ "prompt" message: @ "image uploaded successfully! "Delegate: nilcancelButtonTitle: @" OK "otherButtonTitles: nil];
[Alertshow];
}
-(Void) requestedFail
{
UIAlertView * alert = [[UIAlertViewalloc] initWithTitle: @ "prompt" message: @ "Image Upload Failed! "Delegate: nilcancelButtonTitle: @" OK "otherButtonTitles: nil];
[Alertshow];
}
Use the php File upload. php
Header ("Content-type: text/html; charset = UTF-8 ");
Print_r ($ _ FILES ['file']);
$ Filename = $ _ FILES ['file'] ['name'];
If (! $ _ FILES ['file'] ['error']) {
If (move_uploaded_file ($ _ FILES ['file'] ['tmp _ name'], "./upload/". $ filename ))
{
Echo "File Uploaded successfully ";
} Else {
Echo "File Upload Failed le ";
}
} Else {
Echo "File Upload error ";
}
?>