我想,用户可以更改他们的个人资料图片,但代码不会保存数据库中的图片路径。他正在上传图片并且连接正常。
这里是代码:
function pbchange(){
$csrf = length(isset($_POST['csrf']) ? $_POST['csrf'] : '', 32);
$pbch = length(isset($_POST['pbchange']) ? $_POST['pbchange'] : '', 1);
$error = '';
$name = $_FILES['file']['name'];
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif");
if($pbch == 1 && $csrf == $_SESSION['csrfToken']){
// Check extension
if( in_array($imageFileType,$extensions_arr) ){
// Convert to base64
$image_base64 = base64_encode(file_get_contents($_FILES['file']['tmp_name']) );
$image = 'data:image/'.$imageFileType.';base64,'.$image_base64;
$query = mysqli_query("Update na_user Set pb=".$image." Where id = '".userout('id')."'");
// Upload file
move_uploaded_file($_FILES['file']['tmp_name'],'upload/'.$name);
}
if($query){
header('Location: ./?p=usersettings&h=pbchange');
exit;
} else {
$error = 'Fehler beim ändern des Profilbild! Bitte versuchen Sie es zu einem späteren Zeitpunkt erneut.';
errormail('MySQL Fehler in "Profilbild ändern", Funktion "pbchange()"');
}
}
return sondertext($error);
}