我只是想从数据库表中获取用户名并将文件上传到以username命名的文件夹中,但它给了我一个错误。这是错误:Parse error: syntax error, unexpected T_STRING in /home/u381071273/public_html/upload/upload.php on line 18
但我无法找到它。我想从数据库表中获取用户名并将其显示在我放置&username
代码:
require("models/db-settings.php");
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
$result = $mysqli->query("SELECT user_name FROM upl_users");
// This will move the internal pointer and skip the first row, we don't want that.
//$row = mysql_fetch_assoc($result);
//echo $row['user_name'];
while ( $row = $result->fetch_assoc() ) {
echo $row['user_name'];}
$dir = "uploads/".$row['user_name']."/";
if (file_exists($UploadedDirectory)) {
mkdir('uploads/".$row['user_name']."/', 0777, true);
}
if(isset($_FILES["FileInput"]) && $_FILES["FileInput"]["error"]== UPLOAD_ERR_OK)
{
############ Edit settings ##############
$UploadDirectory = 'uplaods/".$row['user_name']."/'; //specify upload directory ends with / (slash)
##########################################
/*
Note : You will run into errors or blank page if "memory_limit" or "upload_max_filesize" is set to low in "php.ini".
Open "php.ini" file, and search for "memory_limit" or "upload_max_filesize" limit
and set them adequately, also check "post_max_size".
*/
//check if this is an ajax request
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
die();
}
//Is file size is less than allowed size.
if ($_FILES["FileInput"]["size"] > 5242880) {
die("File size is too big!");
}
//allowed file type Server side check
switch(strtolower($_FILES['FileInput']['type']))
{
//allowed file types
case 'image/png':
case 'image/gif':
case 'image/jpeg':
case 'image/pjpeg':
case 'text/plain':
case 'text/html': //html file
case 'application/x-zip-compressed':
case 'application/pdf':
case 'application/msword':
case 'application/vnd.ms-excel':
case 'video/mp4':
case 'audio/mp3';
break;
default:
die('Unsupported File!'); //output error
}
$File_Name = strtolower($_FILES['FileInput']['name']);
$File_Ext = substr($File_Name, strrpos($File_Name, '.')); //get file extention
$Random_Number = uniqid(); //Random number to be added to name.
$NewFileName = $Random_Number.$File_Ext; //new file name
if(move_uploaded_file($_FILES['FileInput']['tmp_name'], $UploadDirectory.$NewFileName ))
{
die('Success! File Uploaded.');
}else{
die('error uploading File!');
}
}
else
{
die('Something wrong with upload! Is "upload_max_filesize" set correctly?');
}
答案 0 :(得分:3)
mkdir('uploads/".$row['user_name']."/', 0777, true);
应该是:
mkdir('uploads/'.$row['user_name'].'/', 0777, true);
(您在进行连接时使用了不同的字符串锚点 - 使用'
启动了字符串但尝试使用"
将其关闭)
答案 1 :(得分:1)
使用此行:(您可以使用单引号或双引号不要混合)
mkdir("uploads/".$row['user_name']."/", 0777, true);