I'm working on a simple php script that allow me to upload images. File uploads correctly, but when I go to open the image uploaded in the directory there's an errore "you're not authorized to see this file, check the authorization and retry"
<!DOCTYPE html>
<html>
<head>
<title> File upload </title>
<meta charset = "UTF-8" />
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Seleziona il file:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
<?php
$target_dir = "C:\Users\test\Desktop\upload_succeeded\\";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Controllo se il file esiste gia
if (file_exists($target_file))
{
echo "Spiacenti, il file esiste gia'.";
$uploadOk = 0;
}
// Abilitare solo alcuni formati di file
if($fileType != "jpg" && $fileType != "png" && $fileType != "jpeg" && $fileType != "gif" )
{
echo "Spiacenti, solo file JPG, JPEG, PNG & GIF sono abilitati.";
$uploadOk = 0;
}
// Controllo se $uploadOk e' settato a 0 da un errore
if ($uploadOk == 0)
{
echo "Spiacenti, il tuo file non e' stato caricato.";
// Se tutto e' ok prova a caricare il file
}
else
{
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "Il file ". basename( $_FILES["fileToUpload"]["name"]). " e' stato correttamente caricato.";
}
else
{
echo "Spiacenti, c'e' stato un errore nel caricamento del file.";
}
}
?>