嗨,我想从我的 iphone 应用程序将图像发送到我的服务器 php,但我发现 iphone 代码没有结果
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"photo1" ofType:@"jpeg"];
NSURL * url = [NSURL URLWithString:@"http://www.myserver.com/uploadimages.php"];
ASIFormDataRequest *request =
[[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setDelegate:self];
[request setPostValue:@"photo.jpeg" forKey:@"name"];
[request setFile:fileLocation forKey:@"photo"];
[request startSynchronous ];
NSError *error = [request error];
if (!error)
{
NSString *response = [request responseString];
NSLog(@"response:%@",response);
}
php文件代码
<?php
$img = $_POST['photo'];
//connect to the db
$user = '*******';
$pswd = '*******';
$conn = mysql_connect('mysql51-79.perso', $user, $pswd);
mysql_select_db('*******');
$query = "INSERT INTO photos VALUES ('','$img')";
mysql_query($query) or die(mysql_error());
echo "Image id is ".mysql_insert_id();
?>
谢谢您的帮助....