文件名feed1.xls在php中是不可读的 [英] The filename feed1.xls is not readable in php
问题描述
.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_once
ed 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屋!