2

我正在使用 php 中的 wget 命令来下载 css 样式表及其依赖项。

exec ("wget -p --convert-links -nH -nd --no-check-certificate http://infidelphia.com/style.css -P /home/devuser/public_html/Tset/");

有一个样式表和几个图像。当我在命令行中执行它时:

wget -p --convert-links -nH -nd --no-check-certificate http://infidelphia.com/style.css -P /home/devuser/public_html/Tset/

我看到其中一个资源有 404,但下载后其他所有资源都很好。

但是,当我通过 PHP 执行此资源时,跳过此资源后的所有内容。有什么方法可以确保跳过失败的下载/错误并且可以下载其余资产?

4

1 回答 1

2

有时,我使用 php curl 下载文件,例如:

$rutaArchivo = '/home/devuser/public_html/Tset/style.css';
$urlArchivo = 'http://infidelphia.com/style.css';

$fp = fopen ($rutaArchivo, 'w+');
$ch = curl_init($urlArchivo);

curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->httpCode = $httpCode;

curl_close($ch);
fclose($fp);

if ($httpCode != 200) {
    unlink($rutaArchivo);
    echo 'Download error, deleting the empty file';    
} else {
    echo 'Download ok';
}

好样的!

于 2012-05-18T21:08:06.150 回答