2017-07-13 5 views
0

こんにちは私は1-96.icalからファイル名を含むIcalフォルダを持っています。しかしながら、これらのファイルの一部は空です(サイズ0キロバイト)と言うエラー私を投げる:(それがないが、空のとき)、それは残りの部分と続けていく存在しない場合はLaravel php、scandir carry onifファイルが存在しません

[Exception] 
    The file path or URL 'public/ical/96.ics' does not exist. 

しかし、私が何をしたいですのファイルの。あなたのループでチェックする

public function handle() 
    { 
     $files = scandir('public/ical/', 1); 
     $type = "Standard Event"; 
     foreach ($files as $file) { 
     $ical = new ICal('public/ical/'.$file); 
     $events = ($ical->events()); 
     $list = []; 
     foreach($events as $event){ 
      if(!empty($event->rrule)){ 
       $lines = explode("\n", $event->rrule); 
      foreach($lines as $line) { 
       $parts = explode(';', $line); 
       $frequency = $until = $day = $interval = null; 
        foreach($parts as $part) { 
        list($key, $value) = explode('=', $part); 
         switch($key) { 
          case 'FREQ': 
          $frequency = $value; 
          break; 
          case 'INTERVAL': 
          $interval = $value; 
          break; 
          case 'BYDAY' : 
          $day = $value; 
          break; 
          case 'UNTIL' : 
          $until = $value; 
          break; 
          case 'BYMONTH' : 
          $month = $value; 
          break; 
          case 'BYMONTHDAY' : 
          $monthday = $value; 
         } 
        if(empty($until)) { 
         $until = "NULL"; 
        } 
       } 
      $data = [ 
       'startdate' => date("Y-m-d h:i:s", strtotime($event->dtstart)), 
       'endate' => date("Y-m-d h:i:s", strtotime($event->dtend)), 
       'startime' => date("Y-m-d h:i:s", strtotime($event->dtstart_tz)), 
       'endtime' => date("Y-m-d h:i:s", strtotime($event->dtend_tz)), 
       'title' => $event->summary, 
       'type' => $type, 
       'frequency' => $frequency, 
       'interval' => $interval, 
       'weekday' => $day, 
       'monthday' => $monthday, 
       'month' => $month, 
       'until' => date("T-m-d h:i:s", strtotime($until)), 
       'description' => $event->description 
      ]; 
      array_push($list, $data); 
     } 
    } 
} 
    $this->info("Event Retrieved"); 
    Event::insert($list); 
    } 
} 
+0

これには何らかのライブラリを使用していますか? ICalクラスは何をしますか? – Jerodev

+0

それは、ライブラリファイルを読み取るだけのライブラリです –

答えて

-1

使用LaravelのFile図書館:

foreach ($files as $file) { 
    if(!File::exists('public/ical/'.$file)) continue; // skips to the next iteration of the loop 
    $ical = new ICal('public/ical/'.$file); 

File::exists()が動作しない場合は、Storage::exists()を試してみてください。私は彼らがどこかのラインに沿って名前を変えたと信じています。

+0

私は両方を試しました、ファイルが機能せず、記憶装置が私に許可を拒否しました –

関連する問題