我试图上传文件使用窗体并将它们放入与登录的用户名对应的文件夹中。我如何使它上传该文件放入尚未创建的文件夹中。在这种情况下,该文件夹应该根据用户名$ user。上传文件里面还不存在的文件夹在php
下面是我的代码:
dbptft.php
$user = $_SESSION['username'];
if (login_check($mysqli) == true) : ?>
<p>Welcome <?php echo htmlentities($user); ?>!</p>
<?php
$directorypath = "/uploads/". $user;
mkdir($directorypath, 0644);
$target_path = "$directorypath/";
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
这是我的形式
<form method="post" enctype="multipart/form-data" action="dbptft.php">
<input type="file" name="uploadedfile">
<input type="submit" class="submit" id="submit" value="Submit" />
错误:
Welcome S00024972!
Warning: mkdir(): No such file or directory in /home/aukwizcq/public_html/ptft/dbptft.php on line 19
Warning: move_uploaded_file(/uploads/S00024972/Capture.PNG): failed to open stream: No such file or directory in /home/aukwizcq/public_html/ptft/dbptft.php on line 25
Warning: move_uploaded_file(): Unable to move '/tmp/phpubGytY' to '/uploads/S00024972/Capture.PNG' in /home/aukwizcq/public_html/ptft/dbptft.php on line 25
There was an error uploading the file, please try again!Error : (0)
dbptft.php有上传文件的权限吗? – Zerquix18
@ Zerquix18每当我改变它的权限,它会给我错误。它不应该是权限应该改变的文件夹吗? –