Path: C:\
<?php
/**
* foto_proxy.php
* Serve imagens armazenadas no compartilhamento de rede \\192.168.0.202\JotForm_New\fotos_jotform_New
* Parâmetro GET: ?path=<caminho_relativo_salvo_no_banco>
*/
// Autenticar na rede para acessar as fotos no servidor 202
@shell_exec('net use \\\\192.168.0.202\\JotForm_New /user:dev.transwar War@2026 2>&1');
$baseDir = '\\\\192.168.0.202\\JotForm_New\\fotos_jotform_New\\';
$relativePath = isset($_GET['path']) ? $_GET['path'] : '';
if (empty($relativePath)) {
http_response_code(400);
exit('Path inválido.');
}
// O banco pode estar salvando o caminho absoluto, por exemplo:
// \\192.168.0.202\JotForm_New\fotos_jotform_New\... ou M:\fotos_jotform_New\...
$fullPath = $relativePath;
// Normaliza barras
$fullPath = str_replace('/', DIRECTORY_SEPARATOR, $fullPath);
// Se o banco salvou usando o disco M:\
if (strpos(strtoupper($fullPath), 'M:\\') === 0) {
// Substitui "M:\" pelo caminho de rede real, pois o Apache pode não ter o M: mapeado
$fullPath = '\\\\192.168.0.202\\JotForm_New\\' . substr($fullPath, 3);
}
// Se por algum motivo for só o caminho relativo, adicione o baseDir
elseif (strpos($fullPath, '\\\\') !== 0 && strpos($fullPath, ':') === false) {
$fullPath = $baseDir . ltrim($fullPath, '\\/');
}
if (!file_exists($fullPath) || !is_file($fullPath)) {
http_response_code(404);
// Retorna um placeholder em caso de arquivo não encontrado
header('Content-Type: image/svg+xml');
echo '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="150" viewBox="0 0 200 150">
<rect width="200" height="150" fill="#f0f0f0"/>
<text x="100" y="70" text-anchor="middle" font-family="Arial" font-size="13" fill="#999">Foto não encontrada</text>
<text x="100" y="90" text-anchor="middle" font-family="Arial" font-size="11" fill="#bbb">Arquivo ausente</text>
</svg>';
exit;
}
$ext = strtolower(pathinfo($fullPath, PATHINFO_EXTENSION));
$mimeTypes = [
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'webp' => 'image/webp',
'pdf' => 'application/pdf',
];
$mime = isset($mimeTypes[$ext]) ? $mimeTypes[$ext] : 'application/octet-stream';
header('Content-Type: ' . $mime);
header('Content-Length: ' . filesize($fullPath));
header('Cache-Control: private, max-age=86400');
readfile($fullPath);
exit;