<?php

$CoID = "";
$Prod_Code = "";



if (isset($_POST["CoID"])) {
    $CoID = $_POST["CoID"];
} else {
    $CoID = $_GET["CoID"];
}

if (isset($_POST["FileName"])) {
    $FileName = $_POST["FileName"];
} else {
    $FileName = $_GET["FileName"];
}

$filename = trim($CoID) . "_photos/" . $FileName . ".jpg";
if (!file_exists($filename)) {
    if (isset($_POST["substitute"])) {
        $substitute = $_POST["substitute"];
    } elseif ((isset($_GET["substitute"]))) {
        $substitute = $_GET["substitute"];
    } else {
        $substitute = "0";
    }
    if ($substitute == 1) {
        $filename = "imgplaceholder.jpg";
    }
}

if (file_exists($filename)) {
    $data = file_get_contents($filename);
    $mime = "image/jpg";
    header('Content-Type: "' . $mime . '"');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header("Content-Transfer-Encoding: binary");
    header('Expires: 0');
    header('Pragma: no-cache');
    header("Content-Length: " . strlen($data));
    exit($data);
} else {

    echo null;
}
?>

