Php 上传白色图像
我正在使用ASIHTT将数据发布到服务器,所有数据都会按原样接收 我正在上传图像Php 上传白色图像,php,iphone,file-upload,asihttprequest,image-uploading,Php,Iphone,File Upload,Asihttprequest,Image Uploading,我正在使用ASIHTT将数据发布到服务器,所有数据都会按原样接收 我正在上传图像 [request1 setData:imageData withFileName:@"upload.png" andContentType:@"image/png" forKey:@"Image"]; 其中imageData是NSData -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMedia
[request1 setData:imageData withFileName:@"upload.png" andContentType:@"image/png" forKey:@"Image"];
其中imageData是NSData
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"] ;
UIGraphicsBeginImageContext(CGSizeMake(320,480));
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGSize kMaxImageViewSize = {.width = 100, .height = 100};
//[self resizeImage:newImage newSize:kMaxImageViewSize];
imageData=UIImageJPEGRepresentation([self resizeImage:newImage newSize:kMaxImageViewSize], 0.5);
}
- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGImageRef imageRef = image.CGImage;
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);
CGContextConcatCTM(context, flipVertical);
// Draw into the context; this scales the image
CGContextDrawImage(context, newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease(newImageRef);
UIGraphicsEndImageContext();
return newImage;
}
这就是我重新调整图像大小的方法。我遇到的问题是,当图像保存在服务器上时,我只会得到一个白色图像,一个空白图像。是服务器问题还是我没有从应用程序发送的东西
编辑
这是我的服务器代码
$filename="upload";
$target_path = "uploads/";
$target_path = $target_path .$filename.".png";
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
echo "uploaded an image";
} else{
echo "There was an error uploading the file, please try again!";
}
if(newImagesTaken.size.width>320 | | newImagesTaken.size.height>480){
//调整图像大小
浮动实际高度=newImagesTaken.size.height;
float actualWidth=newImagesTaken.size.width;
浮动高度=实际宽度/实际高度;
float maxRatio=self.view.frame.size.width/self.view.frame.size.height;
if(imgRatio
没有帮助。在我看来,这可以是一个服务器(php)problem@Spire对如果它仍然不工作,那么Web服务端一定有问题吗?你有php端的代码吗?我可以帮你找到这个。Thanksher是处理异常的最好例子。您上载或试图替换服务器上同名的文件。ti是一个服务器错误,但感谢您对我的问题感兴趣
if (newImagesTaken.size.width > 320 || newImagesTaken.size.height > 480) {
// resize the image
float actualHeight = newImagesTaken.size.height;
float actualWidth = newImagesTaken.size.width;
float imgRatio = actualWidth/actualHeight;
float maxRatio = self.view.frame.size.width/self.view.frame.size.height;
if(imgRatio < maxRatio){
imgRatio = self.view.frame.size.height / actualHeight;
actualWidth = imgRatio * actualWidth;
actualHeight = self.view.frame.size.height;
}
else{
imgRatio = self.view.frame.size.width / actualWidth;
actualHeight = imgRatio * actualHeight;
actualWidth = self.view.frame.size.width;
}
CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
UIGraphicsBeginImageContext(rect.size);
[newImagesTaken drawInRect:rect];
newImagesTaken = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
/////////////////////////////////////////////////////////////////////////////
NSData *imageData = UIImageJPEGRepresentation(newImagesTaken, 1.0);
[request addData:imageData withFileName:@"ByDefault.jpeg" andContentType:@"image/jpeg" forKey:@"Filedata"];
$target_path = "uploads/";
$target_path = $target_path . $_FILES['media']['name'];
if(move_uploaded_file($_FILES['media']['tmp_name'],$target_path)) {
echo "The file ". basename( $_FILES['media']['name']).
" has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
}