我正在用DropzoneJS做一个简单的网站来上传文件,并在我的数据库中插入一些关于上传者的信息,文件类型等。
但问题是我在'upload_log
'中没有看到任何内容文件上传后的表格
这是我的upload.php代码:
$ds = DIRECTORY_SEPARATOR;
$foldername = "../common/uploads";
if (!empty($_FILES)) {
$fileupload = basename( $_FILES['file']['name']);
$fileType = $_FILES['file']['type'];
$fileSize = $_FILES['file']['size'];
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $foldername . $ds;
$targetFile = $targetPath. $fileupload;
move_uploaded_file($tempFile,$targetFile);
$upload_info = "Filetype : <b>".$fileType."</b> <br>File size : <b>".$fileSize."</b><br>File name : <b> ".$fileupload."</b>";
add_to_log($_SESSION['username'], 'upload', $upload_info);
}
函数“add_to_log”:
function add_to_log($usr, $type, $info) {
$servername = 'localhost';
$dbname = 'foo';
$username = 'root';
$password = 'foo';
try
{
$bdd = new PDO('mysql:host='.$servername.';dbname='.$dbname.'', $username, $password);
}
catch(Exception $e)
{
die('DB error');
}
$req = $bdd->prepare('INSERT INTO upload_log(type, user, info) VALUES(:type, :user, :info)');
$req->execute(array(
'type' => $type,
'user' => $user,
'info' => $info
));
}