Я пытаюсь загрузить файл и затем вставить имя файла в базу данных.
Ниже приведен мой код:
<?php
//connecting to database
session_start();
include('/applications/MAMP/htdocs/connect.php');
$u = $_SESSION['username'];
if (!empty($_FILES)) {
$file = $_FILES['Filedata'];
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
$n = $file['name'];
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
mysqli_select_db($connect,"people");
$i = "update users set filelocation = '$n' where sessionusername = '$u'";
$q = mysqli_query($connect,$i);
// } else {
// echo 'Invalid file type.';
// }
}
?>
Файл успешно загружен, но имяне обновляется в базе данных.
Пожалуйста, помогите мне.