我是php Web服务的新手,尝试使用来自目标C的php web服务上传图像。实际上,我必须在服务器上传一个图像并将其url保存在mySQL数据库中。但我无法做到这一点。以下是我的代码:
$file_name = substr ( md5(uniqid(rand(),1)), 5, 15);
$uploaddir = 'uploading/';
$file = basename($_FILES['userfile']['name']);
$newname = $file_name . $file;
$uploadfile = $uploaddir . $newname;
$name=$_GET['username'];
$email=$_GET['email'];
$pwd=$_GET['password'];
$phone=$_GET['phone'];
$fb_user=$_GET['facebook_user'];
$fb_pwd=$_GET['facebook_pwd'];
$twitter_user=$_GET['twitter_user'];
$twitter_pwd=$_GET['twitter_pwd'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
$query="INSERT INTO `user_master` (`name`,`email`,`password`,`phone`,`facebook_user`,`facebook_pwd`,`twitter_user`,`twitter_pwd`,`followers_no`,`following_no`,`profile_view_no`,`profile_photo`) VALUES ('$name','$email','$pwd','$phone','$fb_user','$fb_pwd','$twitter_user','$twitter_pwd',0,0,0,'$uploadfile')";
if(!mysql_query($query)) die('Error : '.mysql_error());
$id= mysql_insert_id();
mysql_close();
echo json_encode(array("response_code"=>"1","response_message"=> "Successful Transaction","UserId"=>"$id"));
}
else
{
echo json_encode(array("response_code"=>"2","response_message"=> "Please try Again."));
return;
}
我得到的结果是“Plase再试一次”。任何帮助将不胜感激。
提前致谢