English 中文(简体)
自动取款机
原标题:upload image from iphone to the server folder

我发现,从网上上载到从电话到服务器机夹的图像上,只有几台幻灯,显示使用服务器旁打字机。

<?php
$uploaddir =  uploads/ ;
$file = basename($_FILES[ userfile ][ name ]);
$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES[ userfile ][ tmp_name ], $uploadfile)) {
        echo "Uploaded!";
}else{
   echo "Not Uploaded!";
}
/>

是没有上述代码将图像直接上载到服务器夹的档案材料,

让我说一下,我想上载到<编码>http://111.22.333.44/mysite/pics/。 w/o 任何服务机方说明,如果能够做到这一点,

最佳回答
/*
  turning the image into a NSData object
  getting the image back out of the UIImageView
  setting the quality to 90
 */
 NSData *imageData = UIImageJPEGRepresentation(image.image, 90);
 // setting up the URL to post to
 NSString *urlString = @"http://iphone.zcentric.com/test-upload.php";

 // setting up the request object now
 NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
 [request setURL:[NSURL URLWithString:urlString]];
 [request setHTTPMethod:@"POST"];

 /*
  add some header info now
  we always need a boundary when we post a file
  also we need to set the content type

  You might want to generate a random boundary.. this is just the same 
  as my output from wireshark on a valid html post
 */
 NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
 NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
 [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

 /*
  now lets create the body of the post
 */
 NSMutableData *body = [NSMutableData data];
 [body appendData:[[NSString stringWithFormat:@"
--%@
",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
 [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name="userfile"; filename="ipodfile.jpg"
"] dataUsingEncoding:NSUTF8StringEncoding]];
 [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream

"] dataUsingEncoding:NSUTF8StringEncoding]];
 [body appendData:[NSData dataWithData:imageData]];
 [body appendData:[[NSString stringWithFormat:@"
--%@--
",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
 // setting the body of the post to the reqeust
 [request setHTTPBody:body];

 // now lets make the connection to the web
 NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
 NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

 NSLog(returnString);

这部法律将有助于你们......。

问题回答

如果你设立网站服务器,允许PUT方法你这样做。 99%的网络服务器只允许使用GET和POST方法。

在从未这样做的情况下,我可以给你很多帮助。 这里是我从谈起的一页:

http://www.w3.org/QA/2008/10/underactive-http-put.html





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签