抱歉我的英文。我使用表单发送文件,然后我想使用$ _SESSION创建用户的目录,在那里将存储该文件。创建目录但不会发送到“用户会话”目录。文件被发送到我的“上传”目录的根目录(而不是上传/ $ _ SESSION ['myusername'] /。我认为这是因为“/”缺少但我尝试了不同的东西并且语法错误。任何帮助将不胜感激我的实际代码是:
<?php
session_start();
$target_dir = 'uploads/'.$_SESSION['myusername'];
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 20000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
答案 0 :(得分:1)
您必须在路径的最后添加斜杠,以便路径完成移动文件:
maven-surefire-plugin