現在我厭倦了這個問題,一直試圖修復它,因爲2-3天。多圖像寫入問題
問題:
我下載某些圖像,然後用PHP腳本編寫他們的磁盤。
圖像的高分辨率可能在7000像素左右。數據正在正確下載。
當我寫上文件的這些數據,有些時候1圖像獲取寫,有時2,3等
該腳本不顯示任何錯誤,只是打破。 我無法訪問服務器日誌,也無法檢查這些日誌。
它破壞後curl_get_contents,意味着我寫文件,如果我評論該部分它正常工作。
下面是代碼:
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
ini_set('max_execution_time', 3000);
include_once("../config.php");
include_once("../utils.php");
$DIR = "../wallpapers";
$URL = "Website url";
$info = array();
$dom = new domDocument;
@$dom->loadHTML(file_get_contents($URL));
$dom->preserveWhiteSpace = false;
$links = $dom->getElementsByTagName('img');
$i = 0;
foreach ($links as $tag){
$iurl = $tag->getAttribute('src');
$lastHyphenAt = strrpos($iurl, "-");
$iurl = substr ($iurl, 0, $lastHyphenAt).".jpg";
$info[$i]["url"] = $iurl;
$info[$i]["name"] = basename($iurl);
$i++;
}
foreach($info as $item){
$url = $item["url"];
$name = $item["name"];
if(!file_exists($DIR."/".$name)){
echo "Downloading: ".$url."<br><br>";
$data = curl_get_contents($url);
$file = fopen($DIR."/".$name,"w") or die('Cannot open file: '.$my_file);
fwrite($file,$data);
fclose($file);
}else
echo "Exists ".($DIR."/".$name)."<br><br>";
}
?>
我想補充一個符合的var_dump($名字)在fopen之前,只是爲了檢查變量的值是否爲 – roeb
這個名字是好的,因爲它已經下載了幾張圖片,當我再次執行api時,它下載了很少的圖片。但不是一勞永逸。 – viv