php - 文件未上传到特定路径
问题描述
我正在尝试以特定路径上传文件,不幸的是 2 个警告阻止我完成上传:/
mkdir(): 中没有这样的文件或目录
move_uploaded_file(Candidatures/xxxx/index.jpeg):无法打开流:
我做错了什么??
$uploadState = "";
if(!empty($_FILES['upload_CoveringLetter']))
{
$uploadState = 1;
$file_name = $_FILES['upload_CoveringLetter']['name'];
$file_size = $_FILES['upload_CoveringLetter']['size'];
$file_tmp = $_FILES['upload_CoveringLetter']['tmp_name'];
$file_type = $_FILES['upload_CoveringLetter']['type'];
$file_ext = strtolower(end(explode('.',$_FILES['upload_CoveringLetter']['name'])));
$extensions = array("odt","doc","docx","pdf","jpeg", "jpg");
if(in_array($file_ext, $extensions) === false)
{
$uploadState = 0;
header('Location: ../addCandidacy.php');
}
else
{
if(!file_exists("Candidatures/".$Candidacy['candidacyType']) && !is_dir("Candidatures/".$Candidacy['candidacyType']))
{
mkdir("Candidatures/".$Candidacy['candidacyType']);
}
move_uploaded_file($file_tmp, "Candidatures/".$Candidacy['candidacyType']."/".$file_name);
$Candidacy['upload_CoveringLetter'] = $_SERVER['DOCUMENT_ROOT'];
}
}
解决方案
您的代码有错误
mkdir("Candidatures/".$Candidacy['candidacyType']);
它应该是
mkdir('Candidatures/'.$Candidacy['candidacyType'],0777, true);
推荐阅读
- c# - 从通用接口转换为对象返回 null
- opencv - 图像配准的边缘/结构匹配
- buildroot - Buildroot 构建问题
- java - 链接多个 CompletableFuture 调用,每个调用都有自己的异常逻辑是一种好习惯吗?
- c# - 将对象对齐到中心
- java - Jenkins 级别的 ant 插件将使用系统或自定义 java home
- php - 使用 Eloquent 查询相关记录
- google-sheets - 使用随机不重复的行重复多列
- android-studio - 使用 kotlin 在 android 中创建自定义微调器适配器
- python - 使用 tweetpy 获取转发者的数量