PHP远程读取excel文件,怎么读取??
PHPExcel能远程读取excel文件吗?即读取其他服务器上的文件!
或者有没有其他好的方法能实现?
求方法…
——解决方案——————–
先用file_get_contents或者curl把文件取回来用phpexcel打开即可
——解决方案——————–
先把远程的弄到本地里。
最简单代码是:
<br />file_put_contents('abc.xls',file_get_contents('http://www.xx.com/abc.xls'));<br />
——解决方案——————–
PHPExcel 通过 PHPExcel_Shared_OLERead 类的 read 方法读取文件
但 read 方法里使用了 is_readable 函数来确认文件是否存在,而 is_readable 不能作用于 url
所以不可直接远程读取
但若绕过 is_readable 函数的话,就是可以的
public function read($sFileName)<br /> {<br /> // Check if file exists and is readable<br /> if(!is_readable($sFileName)) {<br /> throw new Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");<br /> }<br /><br /> // Get the file data<br /> <div style="color:transparent">本&文来源gaodai^.ma#com搞#代!码网</div><strong>搞gaodaima代码</strong> $this->data = file_get_contents($sFileName);<br />
——解决方案——————–
直接注释代码就好了嘛
或者试用tempnam生成临时文件,记得要删