123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- defined('BASEPATH') or exit('No direct script access allowed');
-
- class FileDownload extends CI_Controller
- {
-
- protected $rutaDiaria = FCPATH . "DOWNLOADS/DAILY/";
- protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/";
- protected $enlaceAtom = "";
-
- public function __construct()
- {
- parent::__construct();
- $this->load->library('Feed');
- $this->load->helper('file');
- $this->load->helper('xml');
-
- }
-
- public function index()
- {
- $files = get_filenames($this->rutaDiaria, true);
-
- foreach ($files as $file) {
- $entrada = file_get_contents($file);
- $xml = new SimpleXMLElement($entrada);
- $deletedEntrys = $xml->children('at', true);
- $result1 = $xml->entry->children('cac-place-ext', true);
- $result2 = $xml->entry->children('cac-place-ext', true)->ContractFolderStatus->children('cac-place-ext', true);
- $result3 = $xml->entry->children('cac-place-ext', true)->ContractFolderStatus->children('cac', true);
- $result4 = $xml->entry->children('cac-place-ext', true)->ContractFolderStatus->children('cbc', true);
- }
- }
-
- private function downloadProcess()
- {
- $fileName = basename(URL_DIARIA);
- $this->downloadFile($fileName, URL_DIARIA, $this->rutaDiaria);
-
- $archivoAtom = $this->getFile($this->rutaDiaria . $fileName);
- $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
-
- while ($nuevoAtomAttrNext !== "") {
-
- $fileName = basename($nuevoAtomAttrNext);
- $this->downloadFile($fileName, $nuevoAtomAttrNext, $this->rutaDiaria);
- $archivoAtom = $this->getFile($this->rutaDiaria . $fileName);
-
- $nuevoAtomAttrNext = $this->readNextAttribute($archivoAtom);
- }
- }
-
- private function getFile($url = URL_DIARIA)
- {
-
- $feed = implode(file($url));
- $xml = simplexml_load_string($feed);
- $json = json_encode($xml);
- $array = json_decode($json, true);
-
- return $array;
- }
-
- private function readNextAttribute($archivo)
- {
- $enlace = "";
- foreach ($archivo['link'] as $row) {
- $attrNext = $row['@attributes']['rel'];
- $attrHref = $row['@attributes']['href'];
-
- if ($attrNext === "next") {
- $enlace = $attrHref;
- }
- }
-
- return $enlace;
- }
-
- private function newFolder($rutaFinal)
- {
- $result = false;
- if (!is_dir($rutaFinal)) {
- $result = mkdir($rutaFinal);
- }
-
- return $result;
- }
-
- private function downloadFile($fileName, $url, $ruta)
- {
- if (file_put_contents($ruta . $fileName, file_get_contents($url))) {
- return true;
- } else {
- return false;
- }
- }
-
- }
|