Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Plik nielubiący CRONA...
JamalBIG
post
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 1
Dołączył: 16.01.2008
Skąd: Świnoujście

Ostrzeżenie: (0%)
-----


Witam

Mam problem z plikiem ktory chce aby byl 'obslugiwany' cronem... Wszystkie foldery jak i sam plik jest ustawiony na chmod 777, administrator serwera posprawdzal ustawienia komend i wszystko jest w porzadku (wczesniej inny plik dzialal na tej samej komendzie bez problemu)... Nie majac juz zadnego pomyslu na to czym moze byc to spowodowane chcialbym prosic Was o pomoc... Skrypt dziala bez problemowo uruchamiany w przegladarce... Ponizej przedstawiam skrypt tego pliku:
  1. <?php
  2. require_once("mainfile.php");
  3.  
  4. global $prefix, $db;
  5.  
  6.  
  7.  $czas = 30; // Co ile ma by aktualizacja
  8.  
  9.  $adres = "http://adres.kanalu.rss"; // Adres URL do kanau RSS
  10.  $liczba = 30; // Iloc nagwkw newsw, ktre maj by wyswietlane
  11.  $autoupdate = TRUE;
  12.  $trunc = FALSE;
  13.  $delim = FALSE;
  14.  
  15. if (@fopen($adres,"r")) { // Sprawdza czy ma dostp do kanau RSS
  16.  
  17.      $rssHandle = fopen($adres,"r") ; // Otwiera plik kanau RSS
  18.  
  19.      while (!feof($rssHandle)) {
  20.          $rssData .= fgets($rssHandle);
  21.      }
  22.  
  23.      $tag = "item ";
  24.      $rssData =  preg_replace("/<" . $tag . "(.|s)*?>/","<item>",$rssData);
  25.      $rssData = chop($rssData); // Usuwanie pustych spacji z koca linijek  
  26.      $rssData = ereg_replace("[r,\n]", "", $rssData); // Usuwwanie pustych linijek
  27.      $rssData = strstr($rssData,"<item>"); // Usuwanie wszystie przez <item>.
  28.      $rssData = str_replace("<item>","", $rssData); // usuwanie tagu <item>
  29.      $rssData = urldecode($rssData); // Zamiana wszystkich: %20 na spacje.
  30.      $rssData = str_replace(strstr("</channel>",$rssData),"",$rssData);
  31.      $rssArray = explode("</item>",$rssData); // Tworzenie tablicy z nagwkami
  32.  
  33.        $title = array();
  34.      $link = array();
  35.      $image = array();
  36.      $url = array();
  37.  
  38.      $x = 0;
  39.      while($x < $liczba) {
  40.          $link[$x] = strstr($rssArray[$x],"<link>"); // usuwanie wszystkiego przed <link>
  41.        $link[$x] = ereg_replace("<link>","",$link[$x]);
  42.         $link[$x] = str_replace(strstr($link[$x],"</link>"),"",$link[$x]);
  43.         $link[$x] = trim($link[$x]);
  44.        $link[$x] = str_replace(" ","+",$link[$x]);
  45.        $title[$x] = strstr($rssArray[$x],"<title>");
  46.          $title[$x] = ereg_replace("<title>","",$title[$x]); // Usuwanie <title> z czci tytuu newsa
  47.          $title[$x] = str_replace(strstr($title[$x],"</title>"),"",$title[$x]); //  Usuwanie </title> oraz wszystkiego poza nim
  48.          $title[$x] = trim($title[$x]);
  49.        $image[$x] = strstr($rssArray[$x],"<description>");
  50.          $image[$x] = ereg_replace("<description>","",$image[$x]);
  51.          $image[$x] = str_replace(strstr($image[$x],"description>"),"",$image[$x]);
  52.          $image[$x] = str_replace ("&lt;p&gt;&lt;img src=", "", preg_replace("/&gt;&lt;/p&gt;(.|s)*?&gt;&lt;/p&gt;<//","",$image[$x]));
  53.          $image[$x] = trim($image[$x]);
  54.          $url[$x] = strstr($rssArray[$x],"<enclosure url=\"");
  55.          $url[$x] = ereg_replace("<enclosure url=\"","",$url[$x]);
  56.        $url[$x] = str_replace(strstr($url[$x],"/>"),"",$url[$x]);
  57.        $url[$x] = preg_replace("/\" length=\"(.|s)*?\"/","",preg_replace("/type=\"(.|s)*?\"/","",$url[$x]));
  58.          $url[$x] = trim($url[$x]);
  59.          
  60.        
  61.        if ($trunc != FALSE) { $title[$x] = str_replace(substr($title[$x],$trunc),"",$title[$x]); }
  62.        if ($delim != FALSE) { $title[$x] = str_replace(strstr($title[$x],$delim),"",$title[$x]); }
  63.        
  64.            if ($title[$x] == "") { $liczba = $x; break; } // Gdy ju nie ma nagwkw zmienna $liczba przyjmuje warto maksumaln.
  65.        $x++;
  66.      }
  67.  
  68.     $x=0;
  69.     while ($x < $liczba) {// ta ptla zapisuje kady link osobno.
  70.        
  71.        $short_img = preg_replace("/http(.|s)*?files//","",$image[$x]);
  72.        $short_url = preg_replace("/http(.|s)*?files//","",$url[$x]);
  73.        
  74.        if (empty($url[$x])) {
  75.          echo "BRAK ADRESU PLIKU<br>";
  76.        } elseif  (preg_match("/src/i", $short_img)) {
  77.          echo "BLAD ADRESU GRAFIKI<br>";
  78.        } else {
  79.          echo "OPERACJA: ";
  80.          $exist = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_baza_baza WHERE filename='$short_url'"));
  81.          
  82.          if (empty($exist)) {
  83.            echo "PLIK NIE ISTNIEJE - ZAPIS<br>";
  84.            $result = $db->sql_query("INSERT INTO ".$prefix."_baza_waiting (baza_name, baza_photo) VALUES ('$short_url', '$short_img')");
  85.  
  86.            if (!file_exists("waiting_content/$short_img")) {
  87.          $fp = fopen("waiting_content/$short_img", "x+");
  88.              if (!fwrite($fp, file_get_contents($image[$x]))) {
  89.                fclose($fp);
  90.              }
  91.            }        
  92.            
  93.        if (!file_exists("waiting_content/$short_url")) {
  94.              $fp = fopen("waiting_content/$short_url", "x+");
  95.              if (!fwrite($fp, file_get_contents($url[$x]))) {
  96.                fclose($fp);
  97.              }
  98.            }
  99.          } else {
  100.            echo "PLIK <b>$short_url</b> ISTNIEJE JUZ W BAZIE DANYCH<br>";
  101.          }
  102.        }
  103.        $x++;
  104.    }
  105.  
  106. } else {
  107.  
  108.    echo "NIE MOZNA POLACZYC SIE Z ADRESEM <b>$adres</b>";
  109.  
  110. }
  111.  
  112. //DODAWANIE PLIKOW DO BAZY DANYCH
  113. $result = $db->sql_query("SELECT * FROM ".$prefix."_baza_waiting");
  114.    while ($row = $db->sql_fetchrow($result)) {
  115.      $postFields['filex'] = '@' . dirname(__FILE__) . '/waiting_content/'.$row['baza_name'].'';
  116.      $postFields['photo'] = '@' . dirname(__FILE__) . '/waiting_content/'.$row['baza_photo'].'';
  117.      $ch = curl_init('http://adres.mojego.serwera/modules.php?name=Nazwa&file=takeuploadrss');
  118.      curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  119.      curl_exec($ch);
  120.      curl_close($ch);
  121.    }
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 09:13