简体   繁体   English

文件在Laravel中不可读

[英]File not readable in Laravel

Im trying to open a template with PHPExcel, in laravel. 我试图在Laravel中使用PHPExcel打开模板。

$objPHPExcel = PHPExcel_IOFactory::load(URL::to_asset('myfile.xls'));

However, I get a File is not readable error. 但是,我得到一个文件不可读的错误。

When I do this... 当我这样做时...

if(is_readable(URL::to_asset('myfile.xls')){
    echo "is readable";
 } else { echo "nope";}

I get "nope" returned to me. 我得到“不”还给我。

If i echo an image from this same asset directory, it displays fine. 如果我从相同的资产目录中回显图像,则显示正常。

<img src='URL::to_asset('img/test.png')'>

However if i do this....it also return "nope" 但是,如果我这样做...也返回“ nope”

if(is_readable(URL::to_asset(img/test.png')){
    echo "is readable";
 } else { echo "nope";}

What is going on here? 这里发生了什么?

Why if I visit the link in my browser the files display fine. 为什么如果我在浏览器中访问链接,文件显示正常。

yet when I test them for readbility, they return false results?? 当我测试它们的可读性时,它们返回错误的结果?

This is Larave 3 这是Larave 3

Thanks 谢谢

The PHP function is_readable() expects a system file as argument, so does PHPExcel_IOFactory::load() ; PHP函数is_readable()需要一个系统文件作为参数, PHPExcel_IOFactory::load() you are passing a URL instead, which will always fail. 您传递的是网址,但始终会失败。

You need the local system path to the file and use that instead. 您需要文件的本地系统路径,并使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM