需要帮助: 我正在使用一个简单的 PHP 代码将照片上传到远程数据库。但是.. 每次,一张照片的两份副本都会保存在数据库中。 谁能告诉我我做错了什么? PHP代码:
<?PHP
$uploadDir = 'image_folder/';
$uploadDir = 'image_folder/';
if(isset($_POST['Submit'])) //info saving in the variables
{
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath); //moving the photo in the destination
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
echo "".$filePath."";
$query = "INSERT INTO picture (image) VALUES ('$filePath')";
if (mysql_query($query))
{echo "Inserted";}
mysql_query($query) or die('Error loading file!');
}?>
最佳答案
if (mysql_query($query))
{echo "Inserted";}
mysql_query($query) or die('Error loading file!');
你正在调用 mysql_query($query)
两次
关于php - 通过 PHP 在数据库中上传照片时遇到困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17918323/