Reading xls from remote server via PHPExel
-
There's this code:
$file_path_excel = "http://site.ua/system/PHPExcel/my.xls"; function readExelFile($filepath){ require_once "Classes/PHPExcel.php"; //подключаем наш фреймворк $ar=array(); // инициализируем массив $inputFileType = PHPExcel_IOFactory::identify($filepath); // узнаем тип файла, excel может хранить файлы в разных форматах, xls, xlsx и другие $objReader = PHPExcel_IOFactory::createReader($inputFileType); // создаем объект для чтения файла $objPHPExcel = $objReader->load($filepath); // загружаем данные файла в объект $ar = $objPHPExcel->getActiveSheet()->toArray(); // выгружаем данные из объекта в массив return $ar; //возвращаем массив }
$ar=readExelFile($file_path_excel);
foreach($ar as $ar_colls){делаем что то....
On the way that I'm putting the file down, if move through the browser.
a phpexel can't open it.error code
<b>Fatal error</b>: Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open http://.....ua/system/PHPExcel/my.xls for reading! File does not exist.' in ....www/system/PHPExcel/Classes/PHPExcel/Reader/Excel5.php:433
Can you tell me how to get the remote server file?
Thank you.
-
$filename = basename($file_path_excel); $content = file_get_contents($file_path_excel); if (file_put_contents($filename, $content)) { readExelFile($filename); unlink($filename); } else die("Something went wrong");
You have to keep the file in your system locally, then open it.