【问题标题】:You don't have permission to access this resource. Additionally, a 403 Forbidden error was encountered您无权访问此资源。此外,遇到了 403 Forbidden 错误
【发布时间】:2020-05-23 22:53:21
【问题描述】:

我有一个基于核心 PHP 构建的网站。它在 localhost 中运行良好。现在我上传到 public_html 文件夹中的主机中断服务器。当我尝试上传图片时出现错误“您无权访问此资源。此外,在尝试使用 ErrorDocument 处理请求时遇到 403 Forbidden 错误”。请帮助我。这没有给出特定的部分。所有可以选择上传图像的模块都会给出相同的错误。 表单前端代码

<form class="col-md-6" style="margin-left: 25%;background-color: #0D3349;color: white" action="addclientbackened.php" method="post"  enctype="multipart/form-data">
            <h1 style="text-align: center;color: white">Add images for Gallery</h1>
            <br>
            <br>
            <hr>
            <div class="form-group">
                <label for="name">name</label>
                <input type="text" class="form-control" id="name" placeholder="Enter Category name" name="name" required>
            </div>


            <hr>
            <div class="form-group">
                <label for="fpimage">Font Page image</label>
                <input type="file" id="fpimage" name="fpimage" required>
                <hr>

            <input type="submit" class="btn btn-primary" name="save" value="save" style="font-size: 20px;margin-left: 42%">
            <br>
        </form>

支持的表单代码

<?php

    include "db.php";

    $fpimage= $_FILES['fpimage']['name'];
    $check = getimagesize($_FILES["fpimage"]["tmp_name"]);
    if ($check !== false) {

        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
        throw new Exception("file is not and image");
    }

    $target_dir = "client/";
    $target_file = $target_dir . basename($_FILES["fpimage"]["name"]);
    $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));


    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
    }


    else {
        move_uploaded_file($_FILES['fpimage']['tmp_name'], $target_dir . $fpimage);
        $name = $_POST['name'];
        $sql = "insert into hclients(name,image) values('".$name."','".$fpimage."')";
        $result = mysqli_query($connn, $sql);
        if ($result) {
//          header('location:addclient.php');
            echo '<script language="javascript">';
            echo 'alert("Client stored successfuly")';
            echo '</script>';
            echo "<script> location='addclient.php' </script>";
        } else {
            echo mysqli_error($connn);

        }

    }


?>

这是错误的图像

【问题讨论】:

    标签: javascript php


    【解决方案1】:

    这很可能是由您的网络服务器或路径/文件权限引起的。 例如,在 Linux 中,您的路径对于用户 www-data 或 Web 服务器运行的任何人都是不可写的。

    在 Apache web 服务器中,配置文件或 htaccess 文件使目录或文件不可读、不可写等。

    为了解决您的问题,更需要提供系统和网络服务器信息,例如:

    • 操作系统?
    • 网络服务器?
    • Web 服务器配置?
    • 目录权限

    希望这些信息对您有所帮助。

    【讨论】:

    • 我在主机中断服务器上上传了我的网站。而且我没有 .htaccess 文件
    • 您可以尝试在PHP中将文件写入同一目录,例如使用函数file_put_contents($path,$content);查看PHP脚本是否存在权限问题来划分问题。
    猜你喜欢
    • 1970-01-01
    • 2020-05-07
    • 2021-07-03
    • 2022-08-02
    • 2021-12-27
    • 2021-08-17
    • 2020-12-26
    • 2020-05-30
    • 1970-01-01
    相关资源
    最近更新 更多