<?php
header('Access-Control-Allow-Origin: *');;
ini_set('display_errors', 1);
$ch = curl_init();
$realFileName = str_replace("||MCH-ECOM||", "&", $_GET["arq"]);
$realName = str_replace("||MCH-ECOM||", "&", $_GET["name"]);
$fileId = curl_escape($ch, $realFileName);
$fileName = curl_escape($ch, $realName);
if (urlencode(urldecode($_GET["arq"])) === $_GET["arq"]){
//echo 'string urlencoded'.$_GET["arq"];
} else {
//echo 'string is NOT urlencoded'.$_GET["arq"];
}
$url = "https://machen.azureedge.net/".$fileId;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($rescode === 404){
$url = "https://machen.azureedge.net/".urlencode($fileId);
//print_r($url);
//exit;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
curl_close($ch) ;
$newFileName=str_replace(",", "_", $fileName);
$newFileName=str_replace(" ", "_", $newFileName);
$contentType='application/octet-stream';
if(strpos($fileId, ".pdf")>-1){
$contentType='application/pdf';
}
// header('Content-Description: File Transfer');
// header('Content-Type: '.$contentType);
header("Content-Disposition: attachment; filename=\"".$realName."\"");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header("Etag: $fileId.$newFileName");
header('Cache-Control: must-revalidate');
header('Pragma: public');
echo $res
?>