3

Trying to load an .xlsx file from url but it gives error like,

Fatal error: Uncaught InvalidArgumentException: File 
"http://localhost/test/csvfile/samplesms.xlsx" does not exist. in
D:\wamp\www\test\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Shared\File.php on line 137

Loading file with below,

 $filename = "http://localhost/test/csvfile/samplesms.xlsx";
 $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
 $reader->setReadDataOnly(TRUE);
 $spreadsheet = $reader->load($filename);

File is already at given location.

sagar more
  • 91
  • 1
  • 7

2 Answers2

6

loading from URL is not supported in phpoffice/spreadsheet.

sagar more
  • 91
  • 1
  • 7
6

you can load file content using php_get_content or curl and save it temporary locally then load local version of the file

$filename = "http://localhost/test/csvfile/samplesms.xlsx";

$file = file_get_contents($filename);
$inputFileName = 'tempfile.xlsx';
file_put_contents($inputFileName, $file);
/** Load $inputFileName to a Spreadsheet Object  **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
Sunchock
  • 361
  • 4
  • 14
taoufiqaitali
  • 460
  • 5
  • 10