我正在尝试将文件上传到使用 PHP 创建的目录。应用程序应根据用户的 UserID 在根目录内创建一个子目录。(例如文件/14/)。
正在创建目录,但文件没有上传到子目录。
这是代码:
<?php
include("dbConfig.php");
$Username = $_SESSION["username"];
global $userid;
$Password = $_SESSION["password"];
$Password = md5($Password);
$sql = "SELECT UserID FROM users WHERE Username = '".$Username."'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
$userid = $row['UserID'];
}
echo $userid;
$dirname = (string)$userid;
$filename = ("/folder/" . "$dirname" . "/");
if (!file_exists($filename))
{
mkdir("files/$dirname", 0777);
if (isset($_FILES['files'])) {
echo "<div id='files_table'><table class='center'.><tr><td>";
$dest = ("files/" . $dirname . "{$_FILES['files']['name'][$key]}");
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name){
move_uploaded_file($tmp_name, $dest );
echo $_FILES['files']['name'][$key], " uploaded.", "<br>";
}
}else {
if (isset($_FILES['files'])) {
echo "<div id='files_table'><table class='center'.><tr><td>";
$dest = ("files/" . $dirname . "{$_FILES['files']['name'][$key]}");
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name){
move_uploaded_file($tmp_name, $dest );
echo $_FILES['files']['name'][$key], " uploaded.", "<br>";
}
echo "</td></tr></table></div><br><br>";
}
}
}