Пример #1
0
 public static function downloadImage($travelId, $image, $subdir, $url)
 {
     $userId = JFactory::getUser()->get('id');
     if ($userId) {
         require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'imagedownloader.php';
         KelioniuImportasImageDownloaderHelper::downloadImage($travelId, $image, $subdir, $url);
     } else {
         echo 'prisijungimo klaida';
     }
     return null;
 }
 /**
  * Atsiunčia paveikslėlį iš nurodyto adreso į standartinį katalogą.  
  * @param type $image paveikslėlio vardas
  * @param type $travelId kelionės ID - naudojamas pakatologiui sukurti
  * @param type $subdir2 papildomas pakatologis     
  * @param type $url paveikslelio adresas 
  * @return string
  */
 public static function downloadImage($subDir, $image, $subdir2, $url)
 {
     $pathImportas = JPATH_ROOT . DS . 'images' . DS . 'importas';
     KelioniuImportasImageDownloaderHelper::prepareFolder($pathImportas);
     $pathImages = $pathImportas . DS . $subDir;
     KelioniuImportasImageDownloaderHelper::prepareFolder($pathImages);
     //prijungiam papildoma pakatalogi
     if ($subdir2) {
         $pathImages = $pathImages . DS . $subdir2;
         KelioniuImportasImageDownloaderHelper::prepareFolder($pathImages);
     }
     $fullPath = $pathImages . DS . strtolower($image);
     if (!file_exists($fullPath)) {
         //jei dar neatsiustas
         $ctx = stream_context_create(array('http' => array('timeout' => 60)));
         // nustatom minutes timeouta
         $content = file_get_contents($url, false, $ctx);
         if (!empty($content)) {
             file_put_contents($fullPath, $content);
         }
     }
     return $fullPath;
 }