i need to read from excel file using php, the problem is these two lines:
require 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/IOFactory.php';
//Rest of code
Once I add these lines my code blocks , i'm sure the path is ok , i tried './Classes/PHPExcel etc..' doesn't work
When i execute it, it doesn't display anything , i often do echo 'smth', to see where it stops , but here only when i add these lines it stops, I use PHP 4.3 and PHPExcel 1.8
Can you guess where the error comes from ?
If they're not loading, your file paths are incorrect. Simple as that.
Verify your file structure
current folder/root folder that has myfile.php, inside does it have a folder called Classes?
or... did you forget to include /phpexcel/Classes/ ?
default installation (if you followed the instructions)
require 'phpexcel/Classes/PHPExcel.php';
require_once 'phpexcel/Classes/PHPExcel/IOFactory.php';
Add debug code
You can add echo statements in the PHPExcel libraries to see if they are really loading... if they're not... consult step 1.
Try using an earlier version of PHP
To test you can easily download XAMPP or WAMP to setup a local web host and test it out.
I resolved the problem by using PHP EXCEL Reader because i use php 4 wich wont work with this library or with .xlsx files.
now it is done , and my sheet was read , still , only one sheet is read.
Thank you All !
Related
I'm still a bit new to PHP and stumbled across a weird error I can't fix.
I have different util PHP files for different purposes, such as getting user data or basic util functions.
But I can't figure out why PHP does sometimes not find the path when using the require function.
In particular this example:
print 'Huh';
ob_start();
require "/api/connection.php";
ob_end_clean();
HTML shows a working link redirecting to the page, but PHP still can't find the connection file.
Here is my file tree:
So why is that and how can I fix it? Does PHP have another way of linking files or is it something else?
Thanks in Advance
PHP paths are relative to the root of the filesystem, not the document root. Use $_SERVER['DOCUMENT_ROOT'] to get the latter.
require $_SERVER['DOCUMENT_ROOT'] . "/api/connection.php";
I would like to know if there is a way to enable HyperLink with ctrl-click like PHPStorm and Eclipse for PHP files
require_once ("mainfile.php");
include_once ('lib/nusoap/nusoap.php');
And if there is any extension that also allows you to go-to-definition
With Eclipse and PhpStorm i can navigate between functions and files easily...
The problem is: they're too heavy, so i choose VS Code.
I'm developing an extension like this for PHP right now.
This can't work in all scenarios as you can use functions or constants when declaring paths. e.g.
MAIN_DIR . get_template_directory() . 'file.php'
And u can get these paths from external resources (even parsing the whole app won't always work).
If u have multiple 'file.php' in different directories I can't resolve this.
Edit: the extension will give you now a list of files to choose from.
But if a 'file.php' or 'dir/file.php' relates to only one file I can link it.
I'm checking/matching file names and paths with active workspace files.
PHP File Link
Is it possible to "fake" the inclusion of a file ?
I am testing a code base where DI hasn't been implemented and want to include a class file with my own version before it gets required. When it hits the actual require line, I get complaints about the class already being added.
So when I do require_once on the file, I don't want to actually include it, but it to carry on like it did.
You can use include_once() which won't give you breaking errors but will still try and include the file.
My solution was to duplicate the project and change directory before including the configuration files containing require statements: except in the copied directory, the files were empty.
Then I switched back to the current directory.
I am trying to include PHPExcel to a Silverstripe 3 site to export excel sheets. Right now I am just trying to test, but I get this error when trying to do it:
[Warning] require_once(/sitename/mysite/AddOns/PHPExcel/Classes/PHPExcel.php): failed to open stream: No such file or directory
Thing is I know this file exists since I copied it over myself and have rechecked the path over and over. So I decided "well check if the file exists" using this code:
if(!file_exists(Director::baseURL().'mysite/AddOns/PHPExcel/Classes/PHPExcel.php')) {
echo 'sdf';exit;
}
The path is correct (that is where it is saved) according to the error, but- file does not exist. I am also requiring the file in the same way, with no luck
require_once Director::baseURL().'mysite/AddOns/PHPExcel/Classes/PHPExcel.php';
I have tried everything-checking file permissions, referencing parent folders using ../../, calling it directly like AddOns/PHPExcel, moving it to this new AddOns folder (first tried placing the PHPExcel classes on the root and discovered that Silverstripe doesn't read it then :) )
I know I am doing something wrong but for the life of me I cannot see what. Please help
Thanks
BASE_PATH is the best way to access the web root folder.
require_once(BASE_PATH . '/AddOns/PHPExcel/Classes/PHPExcel.php');
Also this is only an issue if you are not using composer, to solve this issue in the correct way you should use composer.
You should consider using composer to include the PHPExcel class, this will avoid the need to manually require the class and will help you with dependency management.
composer require phpoffice/phpexcel
As pointed out Director::baseURL() will return the URL rather than the filepath.
Instead require relative to the file web root like so:
require_once(BASE_PATH . '/AddOns/PHPExcel/Classes/PHPExcel.php');
As pointed out by both Dan and Barry in the other answers, it's preferable to use composer for dependency management.
In a script I include a php library with :
include_once dirname(__FILE__) . "/lib.php";
This way I don't get code assist for the functions in this library in Eclipse.
But if I use :
include_once "lib.php";
code assist does work.
But I want to use dirname(__FILE__) to be sure I'm looking in the right directory for the lib. (this script may be included in another php-script, and then it doesn't work anymore, without using dirname(__FILE__)
Any tips to get code assist working, while still using dirname(__FILE__) ?
In case the file exist in your project (and your project is an Aptana PHP project), you will get the code assist for all the files in the project, no matter if you include or require a file.
In case your files are located outside of your current project (a different project, or somewhere on your disk), you can attach them as an external library.
You can follow the instructions at https://wiki.appcelerator.org/display/tis/PHP+Development#PHPDevelopment-AttachingPHPResources and learn how to do that according to your needs.
Hope that helps.