我正在创建一个网站,在用户页面中,我只是想添加头像(图片),因此使用了Dropzone>> js和css。
就我而言,PHP脚本将上传的图像成功移动到文件夹中(没有任何错误),但图像名称未插入(更新)到我的数据库表中。
user
表具有用于存储图像名称的头像字段。
如果有人可以提供帮助,下面的代码确实存在错误或....
uploads.php
include ('../fonfig/connection.php');
$ds = DIRECTORY_SEPARATOR;
$id = $_GET['id'];
$storeFolder = 'uploads';
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$newname = time();
$dandom = rand(100, 999);
$name = $newname.$random.'.'.$ext;
$query= "UPDATE users SET avatar = '$name' WHERE id=$id";
$res = mysqli_query($dbc, $query);
echo $query.'<br/>';
echo mysqli_error($dbc);
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $name;
move_uploaded_file($tempFile,$targetFile);
}
?>
users.php
<script>
$(document).ready(fucntion(){
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("#avatar-dropzone");
});
</script>
<form action="uploads.php?id=<?php echo $opened['id']; ?>" class="dropzone" id="avatar-dropzone">
<input type="file" name="file"/>
</form>