文件名feed1.xls在php中是不可读的 [英] The filename feed1.xls is not readable in php

查看:258
本文介绍了文件名feed1.xls在php中是不可读的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用zend框架来解析excel文件。我去了 Zend开发者专区,并找到了一个解决方案下载 phpexcelreader 。我在localhost下载了一个项目,并运行代码。当我勉强阅读一个 .xlsx 文件时会产生错误

 文件名feed1.xlsx不可读

我将文件保存在 .xls 格式并运行代码解析文件成功。现在我想在我的项目中开发的 Zend框架中实现。我创建了一个模型,在我的项目中,在我的项目中, require_once ed我的项目顶部的excelreader如下。

  require_once'Excelreader / Excel / reader.php'; 
class ExcelreaderModel extends Zend_Db_Table
{
function readFile()
{
$ data = new Spreadsheet_Excel_Reader();

//设置输出编码。
$ data-> setOutputEncoding('CP1251');

//$data->read('Excelreader/Excel/feed1.xls');
$ data-> read('feed1.xls');
echo'< pre>';
print_r($ data);
echo'< / pre>';
}
}

我在我的控制器中调用了这个模型函数。但是它使用 .xlsx 文件在localhost上发现相同的错误。但是我正在阅读 .xls 文件,该文件由在localhost上的简单项目运行的代码解析。我也在本地运行zend框架。



我的代码有什么问题?或者有什么办法做同样的任务吗?

解决方案

尽可能地告诉你,你看到的错误已经设置通过这一行代码:

  if(!is_readable($ sFileName)){
$ this->错误= 1;
返回false;
}

由于某种原因,它无法读取您要提供的文件,因为有一个权限/用户问题,或文件的路径是错误的。



如果你在一个* nix服务器上,你应该确保用户运行webserver有权读取excel文件。 Web服务器可能运行的不同于拥有该文件的用户不同的用户。您也可以尝试将权限设置为666。



如果只是找不到文件,提供完整的路径可能有帮助(例如 $ data-> read('/ usr / local / apache2 / htdocs / Excelreader / feed1.xls');


Hi I want to parse an excel file using zend framework. I went to Zend Developer Zone and found a solution to download phpexcelreader. I downloaded the code set a project at localhost and run the code. When I treid to read an .xlsx file it generates an error

The filename feed1.xlsx is not readable

I saved the file in .xls format and run the code parsed the file successfully. Now I want to implement this in my project developed in Zend framework. I created a model, and in my project and require_onceed the excelreader at top of my project like this.

 require_once 'Excelreader/Excel/reader.php';
class ExcelreaderModel extends Zend_Db_Table
{
function readFile()
{
    $data = new Spreadsheet_Excel_Reader();

    // Set output Encoding.
    $data->setOutputEncoding('CP1251');

    //$data->read('Excelreader/Excel/feed1.xls');
    $data->read('feed1.xls');
    echo '<pre>';
    print_r($data);
    echo '</pre>';
}
}

I called this model function in my controller. But it is generating the same error which I found on localhost using .xlsx files. But I am reading .xls file which is parsed by the code running at simple project on localhost.I am also running zend framework at local.

What is wrong in my code? Or is there any way to do the same task.?

解决方案

As best I can tell, the error you are seeing is set by this line of code:

if(!is_readable($sFileName)) {
    $this->error = 1;
    return false;
}

For one reason or another, it cannot read the file you are giving, either because there is a permissions/user issue, or the path to the file is wrong.

If you are on a *nix server, you should make sure the user running the webserver has permission to read the excel file. The web server probably is running as a different user than who owns the file. You can also try setting the permissions to 666.

If it just ins't finding the file, providing a full path may help, (e.g. $data->read('/usr/local/apache2/htdocs/Excelreader/feed1.xls');

这篇关于文件名feed1.xls在php中是不可读的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆