Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to upload image to a server
    primarykey
    data
    text
    <p>I use these code in ios to upload my image</p> <p>It almost the same with another code on the <code>Internet</code></p> <pre><code>NSData *uploadImage = UIImageJPEGRepresentation(self.image, 1) ; NSString *uploadURL = @"http://...../jeff.php" ; NSMutableURLRequest *uploadRequest = [[NSMutableURLRequest alloc] init]; [uploadRequest setURL:[NSURL URLWithString:uploadURL]] ; [uploadRequest setHTTPMethod:@"POST"] ; NSString *boundary = @"---------------------------14737809831466499882746641449"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data;boundary=%@",boundary]; [uploadRequest addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Disposition:form-data; name=\"userfile\"; filename=\"test.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Type: application/octet-streamrnrn\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:uploadImage]]; [body appendData:[[NSString stringWithFormat:@"--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [uploadRequest setHTTPBody:body]; NSData *returnData = [NSURLConnection sendSynchronousRequest:uploadRequest returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"echo:%@",returnString); </code></pre> <p>My PHP is</p> <pre><code>$uploaddir = './uploads/'; $file = basename($_FILES['userfile']['name']); $uploadfile = $uploaddir . $file; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "yes \r\n"; } else { echo "NO \r\n"; } if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "http://...../uploads/{$file}"; } </code></pre> <p>But it's not working</p> <p>My upload folder is /var/www/uploads</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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