javascript - You don't have permission to access this resource. Additionally, a 403 Forbidden error was encountered
Get the solution ↓↓↓I have a website that I built on core PHP.it works perfectly fine in localhost. Now I uploaded on host break server in the public_html folder. when I try to upload an image it gives an error "You don't have permission to access this resource. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request".Please help me with this. This does not give on a specific section. All the modules which have an option to upload an image give the same error. front end code of form
<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>
backened code of 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);
}
}
?>
Here is the image of error
Answer
Solution:
It's most likely caused by your web server, or path/file permissions. For instance, in Linux, your path is not writable for user www-data or anyone the web server run-as.
In Apache web server, the configuration file or the htaccess file made the directory or file not readable, writable, etc.
To solve your problem, it's more required to provide the system and web server information, such as:
- Operating System?
- Web server?
- Web server configuration?
- Directory permissions
Hope this information helps.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: closed without sending a request; it was probably just an unused speculative preconnection
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.