up
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user