Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy the uploaded image do not display properly?
    text
    copied!<p>I uploaded a picture file to the php server, the file can receive on the server side but can not be displayed in Preview , and server logs can not get the image file type, the clip of app code as follows:</p> <pre><code>@interface ImageUploader : NSObject &lt;NSURLConnectionDataDelegate&gt; { ...... } - (id)initWithURL:(NSURL*)theServerURL image:(UIImage*)theImage delegate:(id&lt;ImageUploaderDelegate&gt;)theDelegate; - (void)startUpload; @end @implementation ImageUploader ...... - (void)startUpload { NSURLRequest *request = [self postRequestWithURL:serverURL boundry:BOUNDRY image:image]; connection = [[NSURLConnection alloc]initWithRequest:request delegate:self]; } #pragma mark - Private Methods - (NSURLRequest*)postRequestWithURL:(NSURL*)url boundry:(NSString*)theBoundry image:(UIImage*)theImage { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30]; [request setHTTPShouldHandleCookies:NO]; [request setHTTPMethod:@"POST"]; [request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", theBoundry] forHTTPHeaderField:@"Content-Type"]; NSMutableData *postData = [NSMutableData data]; NSData *imageData = UIImagePNGRepresentation(theImage); if (imageData) { [postData appendData:[[NSString stringWithFormat:@"--%@\r\n", theBoundry]dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"imageFileFromIPhoneApp.png\"\r\n\r\n", FORM_FLE_INPUT]dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:[[NSString stringWithString:@"Content-Type: image/png\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postData appendData:imageData]; } [postData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", theBoundry]dataUsingEncoding:NSUTF8StringEncoding]]; [request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:postData]; return request; } @implementation WonderfulMomentViewController ...... #pragma mark - UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; [picker dismissModalViewControllerAnimated:YES]; // do something with selectedImage and originalImage NSString *queryURL = [NSString stringWithFormat:@"%@/modules/party.php?action=uploadWonderfulImage", HOST_DOMAIN]; ImageUploader *imageUploader = [[ImageUploader alloc]initWithURL:[NSURL URLWithString:queryURL] image:selectedImage delegate:self]; [imageUploader startUpload]; } ...... @end =============================================== the php code below: public function uploadWonderfulImage(){ foreach($_FILES as $key =&gt; $value){ error_log("$key=&gt;$value"); foreach($_FILES[$key] as $subkey =&gt; $subvalue){ error_log("$subkey=&gt;$subvalue"); } } move_uploaded_file($_FILES["uploadFile"]["tmp_name"], $_FILES["uploadFile"]["name"]); } =============================================== the php log below:(note:the value of type is null) [Tue May 22 09:34:43 2012] [error] [client 192.168.55.31] uploadFile=&gt;Array [Tue May 22 09:34:43 2012] [error] [client 192.168.55.31] name=&gt;imageFileFromIPhoneApp.png [Tue May 22 09:34:43 2012] [error] [client 192.168.55.31] type=&gt; [Tue May 22 09:34:43 2012] [error] [client 192.168.55.31] tmp_name=&gt;/private/var/tmp/phpnbb3cf [Tue May 22 09:34:43 2012] [error] [client 192.168.55.31] error=&gt;0 [Tue May 22 09:34:43 2012] [error] [client 192.168.55.31] size=&gt;868591 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload