getFileContent() public method

Gets the content of a single file if available
public getFileContent ( $filePath ) : mixed
$filePath string The full path (including all folders) of the file in the zip
return mixed returns the content or throws an exception
Beispiel #1
0
 public function testNavigationFolderAndHome()
 {
     $this->archive->folder('foo/bar');
     $this->assertEquals('foo/bar', $this->archive->getCurrentFolderPath());
     //----
     $this->file->shouldReceive('isFile')->with('foo')->andReturn(true);
     $this->archive->add('foo');
     $this->assertEquals('foo/bar/foo', $this->archive->getFileContent('foo/bar/foo'));
     //----
     $this->file->shouldReceive('isFile')->with('bar')->andReturn(true);
     $this->archive->home()->add('bar');
     $this->assertEquals('bar', $this->archive->getFileContent('bar'));
     //----
     $this->file->shouldReceive('isFile')->with('baz/bar/bing')->andReturn(true);
     $this->archive->folder('test')->add('baz/bar/bing');
     $this->assertEquals('test/bing', $this->archive->getFileContent('test/bing'));
 }
Beispiel #2
0
 /**
  * Gets the content of a single file if available
  *
  * @param $filePath string The full path (including all folders) of the file in the zip
  * @throws \Exception
  * @return mixed returns the content or throws an exception
  * @static 
  */
 public static function getFileContent($filePath)
 {
     return \Chumper\Zipper\Zipper::getFileContent($filePath);
 }
 public function postEmpresa(Request $request)
 {
     ini_set('max_execution_time', $this->max_time);
     if (!$request->hasFile('empresa')) {
         return response()->json(['error' => "Ya se subio el archivo"], 200);
     }
     $file = $request->empresa;
     if ($file->getClientOriginalExtension() != "xml" && $file->getClientOriginalExtension() != "zip") {
         return response()->json(['error' => "El formato debe de ser xml o zip"], 200);
     }
     try {
         if ($file->getClientOriginalExtension() == "zip") {
             $errores = array();
             $zipper = new Zipper();
             $zipper->make($file->getRealPath());
             $count = 0;
             foreach ($zipper->listFiles() as $file) {
                 $fileExpled = explode(".", $file);
                 if ($fileExpled[count($fileExpled) - 1] == "xml") {
                     $nombre = $file;
                     try {
                         $resp = $this->empresaFiles($zipper->getFileContent($file));
                     } catch (\Exception $e) {
                         $resp = "no";
                         $errMess = $e->getMessage();
                         $errores[] = "Error: {$errMess} en archivo: {$nombre} ";
                     }
                     if ($resp == "yes") {
                         $count++;
                     }
                 }
             }
             if (count($errores) > 0) {
                 return response()->json(['error' => $errores], 200);
             }
         } else {
             $nombre = $file->getClientOriginalName();
             $text = file_get_contents($file->getRealPath());
             $this->empresaFiles($text, false);
         }
     } catch (\Exception $e) {
         return response()->json(['error' => "Archivo: {$nombre} => " . $e->getMessage()], 200);
     }
     return response()->json("yes", 200);
 }