我正在尝试将图像上传到 mysql,当我尝试使用此代码时,似乎它只能插入文件夹名称,但 mysql 表中没有图像文件名,我能知道出了什么问题
if ($_POST['submit'])
{
//get file attribute
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
//start upload process
$location = "avatars/".$name;
move_uploaded_file($tmp_name,$location);
$query = mysql_query("UPDATE users SET imagelocation='$location' WHERE username='$username'");
}
//image form
<form action='upload.php' method='POST' enctype='multipart/form-data'>
File: <input type='file' name='myfile'> <input type='submit' name='submit' value='Upload!'>
</form>
结果:当我尝试在mysql表中上传例如picture.jpg时,它只出现在列上的“avatars/”,而不是“avatars/picture.jpg”