首页 > 解决方案 > IIS8+PHP+samba文件夹不能读写文件夹

问题描述

所以基本上我在xampp上构建了一个网页(php + js),让用户填写表格,并在该表格中他们可以上传多个图像。该站点运行良好,因此我使用 IIS8 将其上传到服务器上的生产环境。表单效果很好,但我无法上传或查看我上传的图像。

图像正在上传到 samba 驱动器,在 xampp 中我没有任何问题,它在 IIS 上的工作方式也是如此,我收到一条错误消息,说我没有权限。我不知道我做错了什么

这是获取图像的代码

    <?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['id'])){
    $id = $_POST['id']; 
    $directory = '\\\\server\\'.$id.'\\';
    $directory = '\\\\server\\'.$id.'\\';
    $local = glob("" . $directory . "{*.jpg,*.gif,*.png}", GLOB_BRACE);
    $img_arr = array();
    if($local){
        $x=1;
    }else{
        $x=0;
    }
    foreach($local as $item)
    {
        $image = $item;
        $imageData = base64_encode(file_get_contents($image));
        $src = 'data: '.mime_content_type($image).';base64,'.$imageData;
        $img_arr [] = array('mime'=> mime_content_type($image),'imgDt'=> $imageData); 
    }
}
if ($x==0){
    $response = [
        'status'=>'falhou',
        'values' => $local
    ];
}else{
    $response = [
        'status'=>'sucesso',
        'values' => $img_arr
    ];
}

header('Content-Type: application/json');
echo json_encode($response);
?>

这是添加图像的代码

if (!file_exists('\\\\server\\'.$tmstp)) {
        mkdir('\\\\server\\'.$tmstp);  
    }
    $uploadDir = '\\\\server\\'.$tmstp.'\\';

    if(!empty($_FILES['anex'])){
        foreach ($_FILES['anex']['name'] as $key=>$ficheiro) {
            $fileName = basename($_FILES['anex']['name'][$key]);
            $tmpname = $_FILES['anex']['tmp_name'][$key]; 
            $targetFilePath = $uploadDir . $fileName; 
            $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION); 
            $allowTypes = array('jpg', 'png', 'jpeg', 'gif'); 
            if(in_array($fileType, $allowTypes)){ 
                if(file_exists($targetFilePath)) {
                    //chmod($targetFilePath,0755); //Change the file permissions if allowed
                    unlink($targetFilePath); //remove the file
                }
                if(move_uploaded_file($tmpname, $targetFilePath)){ 
                    $uploadedFile = $fileName; 
                    if ($i=0){
                        $anex=$fileName;
                        $i++;
                        $uploadStatus = 1;
                        $hf=true;
                    }
                    else{
                        $anex=$anex .';' . $fileName;
                        $uploadStatus = 1;
                        $hf=true;
                        $rspimg = 'Upload fotos com sucesso';
                    }
                }else{ 
                    $uploadStatus = 0; 
                    $rspimg = 'Ouve um erro com o UPLOAD das imagens'; 
                } 
            }else{ 
                $uploadStatus = 0; 
                $rspimg = 'Só JPG, JPEG, PNG ou GIF'; 

            } 
        }
    }else{
        $hf = false;
    }

我已经尝试在 IIS 上创建一个虚拟文件夹,但它仍然无法正常工作

标签: javascriptphpiis-8samba

解决方案


推荐阅读