php - File not readable in Laravel

829

Im trying to open a template with PHPExcel, in laravel.

$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"

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

Thanks

410

Answer

Solution:

The PHP functionis_readable() expects a system file as argument, so doesPHPExcel_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.

People are also looking for solutions to the problem: php - Running a Laravel Artisan command as a new process

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.