This commit is contained in:
Lizandro Guarnizo
2026-02-21 09:23:59 -05:00
parent 61c50df07d
commit ad04c49d27
2 changed files with 16 additions and 2 deletions
+15 -2
View File
@@ -159,9 +159,11 @@ class MediaService {
$tmpFile = tempnam(sys_get_temp_dir(), 'wget_');
$headerArgs = '';
foreach ($headers as $h) {
// Solo pasar headers que wget soporte
$headerArgs .= ' --header=' . escapeshellarg($h);
}
$cmd = 'wget -4 -q -O ' . escapeshellarg($tmpFile) . $headerArgs . ' ' . escapeshellarg($url) . ' 2>&1';
// Intentar con GNU wget primero (soporta --prefer-family=IPv4)
$cmd = 'wget -q --prefer-family=IPv4 -O ' . escapeshellarg($tmpFile) . $headerArgs . ' ' . escapeshellarg($url) . ' 2>&1';
exec($cmd, $output, $exitCode);
if ($exitCode === 0 && file_exists($tmpFile) && filesize($tmpFile) > 0) {
@@ -171,7 +173,18 @@ class MediaService {
return $content;
}
error_log("[MediaService::downloadWithWget] FAIL exit={$exitCode} output=" . implode(' ', $output));
// Fallback sin --prefer-family (BusyBox wget no lo soporta)
$cmd2 = 'wget -q -O ' . escapeshellarg($tmpFile) . $headerArgs . ' ' . escapeshellarg($url) . ' 2>&1';
exec($cmd2, $output2, $exitCode2);
if ($exitCode2 === 0 && file_exists($tmpFile) && filesize($tmpFile) > 0) {
$content = file_get_contents($tmpFile);
unlink($tmpFile);
error_log("[MediaService::downloadWithWget] OK (basic), " . strlen($content) . " bytes");
return $content;
}
error_log("[MediaService::downloadWithWget] FAIL exit={$exitCode}/{$exitCode2} output=" . implode(' ', array_merge($output, $output2)));
if (file_exists($tmpFile)) unlink($tmpFile);
return false;
}