I have the following PHP script to upload images to my site:
function saveImage2Server($input_name)
{
$originalFileName = basename($_FILES[$input_name]["name"]);
$fileType = exif_imagetype($_FILES[$input_name]["tmp_name"]);
$fileSize = $_FILES[$input_name]["size"];
$allowedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_PNG);
$maxSize = 819200;
// first check if the file is of allowed type
if(in_array($fileType, $allowedTypes))
{
//check if the size is under 800kb
if($fileSize<=$maxSize)
{
$dotIndex = strrpos($originalFileName, ".");
$extension = strtolower(substr($originalFileName, $dotIndex));
$newFileName = uniqid().uniqid().$extension;
move_uploaded_file($_FILES[$input_name]["tmp_name"], "../../images/".$newFileName);
return $newFileName;
}
else // if it's above 800kb
{
echo("The file size exceeds 800kb");
header("Location: ../");
die(error);
}
}
else // if the type isn't allowed
{
echo("This file type isn't allowed");
header("Location: ../");
die(error);
}
}
The script works fine on my local server (WAMP), after the files are uploaded I'm able to access them normally. But when on IIS - the files are being uploaded, but when trying to access them, I'm getting this 401 error message: 401 - Unauthorized: Access is denied due to invalid credentials.
What can I or my hosting company do to resolve it?