我只是想知道是否有人可以告诉我我做错了什么。我的目标非常简单。使用dropzone或php上传文件并将记录插入数据库。我能够发布记录,除了一个总是显示“数组”作为条目的字段。我已经尝试更改变量名称,插入和删除引号等无济于事。任何建议将不胜感激。 这是我的代码。
<?php
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = 'uploads'; //2
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
}
$servername = "localhost";
$username = "root";
$password = "***************";
$dbname = "drop";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO uploads (id, file_name)
VALUES (NULL, 'file_name')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
答案 0 :(得分:1)
弄清楚我自己的问题。答案是用$ targetfile替换file_name。现在它按预期工作。感谢。