我有一个UIImageView加载用户的个人资料图片。我添加了一些UIImagePicker功能,现在用户可以通过使用相机或从库中添加来更改配置文件图片。这是代码:从UIImagePicker上传图像到服务器通过php
- (IBAction)cameraAction:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)libraryAction:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
_profilePhoto.image = chosenImage;
UIImageWriteToSavedPhotosAlbum(_profilePhoto.image, nil, nil, nil);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
然后,我有PHP文件上传当前图像到服务器。问题是,php的输入参数是图像文件名称。我会环顾相当多时间,并知道要获取图像名称,首先我需要将其保存到应用程序文档目录,并使用稍后想要的名称对其进行重命名。所以任何人都可以告诉我如何将这个图像保存到应用程序文档目录中,如何获取它以及如何使用我想要的名称对其进行重命名。在此先感谢
这或许可以帮助你 [http://stackoverflow.com/questions/21400842/uploading-selected-image-from-photo-library-using -afnetworking及PHP] [1] [1]:http://stackoverflow.com/questions/21400842/uploading-selected-image-from-photo-library-using-afnetworking-and- php – 2014-10-01 07:34:41