$d = date("d", $this->t); $dir = "tapas/{$y}/{$m}/{$d}"; if (!file_exists($dir)) { mkdir($dir, 0777, true); } foreach ($diarios as $diario => $url) { echo "{$diario}... "; $ext = endsWith($url, 'pdf') ? 'pdf' : 'jpg'; @($f = fopen($url, 'r')); if ($f) { file_put_contents("{$dir}/{$diario}.{$ext}", $f); } echo "done<br>"; } } function download() { $this->download_diarios($this->ejes()); $diarios = array(); $news = array('Ambito' => 'ARG_DAF', 'BuenosAiresHerald' => 'ARG_BAH', 'LaNacion' => 'ARG_LN', 'Clarin' => 'ARG_CLA'); foreach ($news as $diario => $tapa) { $diarios[$diario] = $this->newseum($tapa); } $this->download_diarios($diarios); } } $tapas = new tapas(); if (isset($_GET['d'])) { $tapas->days_before($_GET['d']); } $tapas->download();