首页 > 解决方案 > 文件未上传到特定路径

问题描述

我正在尝试以特定路径上传文件,不幸的是 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'];
    }
}

标签: php

解决方案


您的代码有错误

mkdir("Candidatures/".$Candidacy['candidacyType']);

它应该是

mkdir('Candidatures/'.$Candidacy['candidacyType'],0777, true);

推荐阅读