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.

2 Answers 2

6

loading from URL is not supported in phpoffice/spreadsheet.

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.