这是我使用 php 在 Mysql 中上传图像的 xcode 代码。NSString *urlString = @"http://www.mysullurpeta.com/iphone/upload.php";
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"world1.jpeg"],90);
NSLog(@"imageView in data %@/n>>>>%d kb",imageData,imageData.length);
NSMutableURLRequest *request= [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
NSLog(@"post data is %@", contentType);
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
[request setHTTPBody:imageData];
NSLog(@"post data is %@",request);
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *str = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"Data ---- %@", str);
------这是我的php脚本
<?php
echo "file from client: " . $_FILES["filename"]["name"];
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
我正在尝试将图像移动到“上传/”文件中。它显示错误无效文件。我在哪里做错了,我不明白。请...帮助我...谢谢