Reputation: 21
I am just wondering if someone can tell me what I'm doing wrong. My goal is pretty simple. Using dropzone or php to upload a file and insert a record into a database. I am able to post the record except for one field which is always showing "array" as the entry. I've tried changing variable names, inserting and removing quotes, etc to no avail. Any suggestions would be greatly appreciated. Here is my code.
<?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);
?>
Upvotes: 1
Views: 507
Reputation: 21
Figured out my own question. The answer is replacing file_name with $targetfile. Now it works as expected. Thanks.
Upvotes: 1