예제 #1
0
 /**
  * アップロードされたCSVファイルの行ごとの処理
  *
  * @param $formFile
  * @return CsvImportService
  */
 protected function getImportData($app, $formFile)
 {
     // アップロードされたCSVファイルを一時ディレクトリに保存
     $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension();
     $formFile->move($app['config']['csv_temp_realdir'], $this->fileName);
     $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName);
     // アップロードされたファイルがUTF-8以外は文字コード変換を行う
     $encode = Str::characterEncoding(substr($file, 0, 6));
     if ($encode != 'UTF-8') {
         $file = mb_convert_encoding($file, 'UTF-8', $encode);
     }
     $file = Str::convertLineFeed($file);
     $tmp = tmpfile();
     fwrite($tmp, $file);
     rewind($tmp);
     $meta = stream_get_meta_data($tmp);
     $file = new \SplFileObject($meta['uri']);
     set_time_limit(0);
     // アップロードされたCSVファイルを行ごとに取得
     $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']);
     $data->setHeaderRowNumber(0);
     return $data;
 }
예제 #2
0
 /**
  * アップロードされたCSVファイルの行ごとの処理
  *
  * @param $formFile
  * @return CsvImportService
  */
 protected function getImportData($app, $formFile)
 {
     // アップロードされたCSVファイルを一時ディレクトリに保存
     $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension();
     $formFile->move($app['config']['csv_temp_realdir'], $this->fileName);
     $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName);
     if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID >= 70000) {
         // Windows 環境の PHP7 の場合はファイルエンコーディングを CP932 に合わせる
         // see https://github.com/EC-CUBE/ec-cube/issues/1780
         setlocale(LC_ALL, '');
         // 既定のロケールに設定
         if (mb_detect_encoding($file) === 'UTF-8') {
             // UTF-8 を検出したら SJIS-win に変換
             $file = mb_convert_encoding($file, 'SJIS-win', 'UTF-8');
         }
     } else {
         // アップロードされたファイルがUTF-8以外は文字コード変換を行う
         $encode = Str::characterEncoding(substr($file, 0, 6));
         if ($encode != 'UTF-8') {
             $file = mb_convert_encoding($file, 'UTF-8', $encode);
         }
     }
     $file = Str::convertLineFeed($file);
     $tmp = tmpfile();
     fwrite($tmp, $file);
     rewind($tmp);
     $meta = stream_get_meta_data($tmp);
     $file = new \SplFileObject($meta['uri']);
     set_time_limit(0);
     // アップロードされたCSVファイルを行ごとに取得
     $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']);
     $ret = $data->setHeaderRowNumber(0);
     return $ret !== false ? $data : false;
 }
예제 #3
0
 public function testCharacterEncodingWithNone()
 {
     // 「〠」は UTF-8 固有の文字
     $text = mb_convert_encoding('〠', 'UTF-8', 'UTF-8');
     $this->actual = Str::characterEncoding($text, array('SJIS-win', 'eucJP-win', 'ASCII'));
     // UTF-8 は検出しない
     $this->assertNull($this->actual);
 }