我有一个用于上传图片的php文件,重命名它,因此它有一个独特的值,可以获取其他用法,上传部分工作,但当我采取变量($ fileNewName)并尝试将其插入到数据库,它没有用。
session_start();
include_once('dbh-inc.php');
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 1000000) {
$fileNameNew = uniqid('',true).".". $fileActualExt;
$fileDestination = '../uploads/' .$fileNameNew;
move_uploaded_file($fileTmpName,$fileDestination);
$sql = "UPDATE stenden_users SET userImagePath = ".$fileNameNew." WHERE userID =" .$_SESSION['u_id'] ;
if ($stmt = mysqli_prepare($conn,$sql)) {
$result = mysqli_stmt_execute($stmt);
if($result == FALSE){
echo "failed";
} else {
echo "success!!!";
}
}
echo "Your image was successfully uploaded! ";
} else {
echo "The size of file is too big";
}
} else {
echo "There was an error uploading your file";
}
} else {
echo "You cannot upload files of this type";
}
答案 0 :(得分:0)
您的SQL语法不正确,您可以将SQL查询更改为:
$sql = "UPDATE stenden_users SET userImagePath = '".$fileNameNew."' WHERE userID =" .$_SESSION['u_id'] ;