php - if photo has uploaded successfully -
I would like to be able to upload a photo to my website and it has a different view controller. And if there is an error for it xyz:
like:
if (! Error) {[self display cigu with identifier: @ "toci and country" sender: self ]; } And {NSERR * error = [request error]; }
How do I upload my photos:
If Objective-C code:
NSData * imageData = UIImagePNGRepresentation ([UIImage imageNamed: @ "image.jpg"]); NSMutableURLRequest * Request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @ "http: //**********************] cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 20.0]; [Set http system: @ "post"]; [Request Set Value: @ "Image / JPG" forHTTPHeaderField: @ "Content Type"]; [Request Set Value: [NSString stringWithFormat: @ "% lu", (unsigned long) [imageData length]] forHTTPHeaderField: @ "content-length"]; [Set http: bbdi: [self imagedatons]]; NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest: Request Rep: Self]; If (connection) ([NSMutableData data] is maintained); } And {nslog (@ "connection to connection"); } [Connection connection]; and imageupload.php : & lt ;? Php $ handle = fopen ("image.jpg", "West Bengal"); // Write Binary Fright ($ handle, $ HTTP_RAW_POST_DATA); fclose ($ handle); Print "received image file."; ? & Gt;
I have also found that there is no loading GIF at the top of the screen of the iPhone, when the image is being uploaded ?:
Edit: NSURLSessionConfiguration * Configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; AFURL session manager * manager = [[ARKRSationman alloc] initWithSessionConfiguration: Configuration]; NS URL * URL = [NSUr URL YouthString: @ "http: // ****************************************************** ]]; NSURLRequest * request = [Ansuarar request with url: URL]; // which makes HTC code? ns URL * Failpth = [Ansuar file URL Vithpath: @ "file: // Path / to / Aimej page"] ; NSURLSessionUploadTask * uploadTask = [manager uploadTaskWithRequest: request fromFile: FilePath progress: completionHandler zero: ^ (NSURLResponse * response, id responseObject, NSError * error) {if (error) {NSLog (@ "error:% @", error); } Other {NSLog (@ "Success:% @% @", Copy Action, feedback object);}}] [[resume upload];
< H3> PHP Always add a check to make sure that you are actually doing something,
you can try it this way: < pre> & lt ;? php if (is_uploaded_file ($ _ files [ 'image'] [ 'tmp_name'])) {$ folder = "upload /"; $ File = basename ($ _FILES [ 'image'] ['Name']); $ Full_path = $ folder. $ File; if (move_uploaded_file ($ _ FILES [ 'image'] [ 'tmp_name'], $ full_path)) {echo "{" success ": true," msg ":" successful upload, we have an image! "}; } Else {echo '{"Success": wrong, "msg": "Upload received! But process failed"}'; }} And {echo '{"success": wrong, "msg": "upload failed! Nothing was uploaded"}'; }? & Gt; Objective C NSData * imageData = UIImagePNGRepresentation ([UIImage imageNamed: @ "image.jpg"]); NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @ "http: // ***************************** Cash Policy: NSURLRequestReloadIgnoringLocalCacheData Timeout Interval: 20.0]; [SetHttp System: @ "Post"] [[Request Set Value: @ "Image / JPG" forHTTPHeaderField: @ "Content Type"]; [Request Set Value: [NSString stringWithFormat : @ "% lu", (unsigned long) [imageData length]] ForHTTPHeaderField: @ "content-length"] [set Actiteepibeediai: [own Cvidetatons]]; // request Ansdiatta message * Wapaseedeta = [Ansuarkne Sending the synchronous request: the request is returning response: zero error: zero]; // JSON serialization for NSDictionary * result = [NSJSNAS algorithm JSONObjectWithData: returnData option: NSJSNRreadingTableContributor Error: Zero]; // parsing JSON bool success = [result [ @ "Success"] boolValue; if (success) {NSLog (@ "success =% @", result [@ "msg"]);} else {NSLog (@ "failed =% @" result [@ "msg" ]);}
Comments
Post a Comment