Note that there are some explanatory texts on larger screens.

plurals
  1. POApple photopicker upload taken picture with php to a mysql database
    text
    copied!<p>i have downloaded the sample code for the photopicker from Apple here : <a href="http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196-Intro-DontLinkElementID_2" rel="nofollow">http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196-Intro-DontLinkElementID_2</a></p> <p>I have modified the section of the code that represent the result of the picture taken (the snap shot button) in the MyViewController.m :</p> <pre><code>// as a delegate we are being told a picture was taken - (void)didTakePicture:(UIImage *)picture { [self.capturedImages addObject:picture]; } </code></pre> <p>Then to use a code similar as this one to push it out to my web server :</p> <pre><code>NSData *imageData = UIImageJPEGRepresentation(**_capturedImages.images**, 90); NSString *urlString = @"http://localhost/upload.php"; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; NSString *boundary = @"---------------------------14737809831466499882746641449"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [request addValue:contentType forHTTPHeaderField:@"Content-Type"]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:imageData]]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPBody:body]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(returnString); </code></pre> <p>The problem that I have is I keep having messages saying that the file cannot be uploaded or the code just crash.</p> <p>I think is is just a matter of accessing correctly the resulting image and push it correctly.</p> <p>Because I do not know how to extract the image from this from MyViewController.m:</p> <pre><code>@property (nonatomic, retain) **NSMutableArray** *capturedImages; </code></pre> <p>The PHP Code for upload.php is :</p> <pre><code>&lt;?php $file = basename($_FILES['userfile']['name']); $uploadFile = $file; $randomNumber = rand(0, 99999); $newName = $randomNumber . $uploadFile; echo $file; echo $uploadFile; echo $randomNumber; echo $newName; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "Temp file uploaded. \r\n"; } else { echo "Temp file not uploaded. \r\n"; } if ($_FILES['userfile']['size']&gt; 300000) { exit("Your file is too large."); } if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) { $postsize = ini_get('post_max_size'); //Not necessary, I was using these $canupload = ini_get('file_uploads'); //server variables to see what was $tempdir = ini_get('upload_tmp_dir'); //going wrong. $maxsize = ini_get('upload_max_filesize'); echo "http://localhost/{$file}" . "\r\n" . $_FILES['userfile']['size'] . "\r\n" . $_FILES['userfile']['type'] ; } ?&gt; </code></pre> <p>Thanks</p> <p>Regis</p>
 

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