PHP Excel 01simple-download-xlsx.php and 07reader.php giving different output - php

I am trying to run 2 example of PHPExcel
01simple-download-xlsx.php and 07reader.php
01simple-download-xlsx.php Working Perfect but this example 07reader.php is showing error mentioned below Why can't understand since last 4 hours.
Any one can kindly tell me why this is happening when the file is using same directory structure.
Warning: require_once(../Classes/PHPExcel/IOFactory.php): failed to
open stream: No such file or directory in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37
Fatal error: require_once(): Failed opening required
'../Classes/PHPExcel/IOFactory.php'
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\manazeschool\software\office_admin\exam_excel\Examples\07reader.php
on line 37

Some of the examples (such as the 01* files) correctly use an absolute pathname __DIR__ . '../Classes/...' to include the main PHPExcel library, which means you don't need to be in the /Examples directory to run them.
Other examples (07reader.php included) simply use a relative pathname '../Classes/...'to include the main PHPExcel library, which means you do need to be in the /Examples directory to run them.
To resolve the issue, either ensure that you're in the /Examples folder when you run these files, or modify the include to use the absolute pathname.
I believe I've now fixed all of these example files to use the absolute pathname in the development branch on github.

Related

Cannot set PHP include_path

I have uploaded all my files in var/www/html and in one of my php files I have this line :
require_once('libraries/stripe/init.php');
the structure of my folders are list this:
www
-html/
-libraries
-> Stripe -> init.php
-register.php
I keep getting this error message:
Warning: require_once(libraries/Stripe/init.php): failed to open stream: No such file or directory in /var/www/html/register.php on line 116
Fatal error: require_once(): Failed opening required 'libraries/Stripe/init.php' (include_path='.:/usr/share/php:/var/www/html/') in /var/www/html/register.php on line 116
my php.ini file used to be like this
include_path= ".:/usr/local/php/pear/"
but based on some answers here i changed it to
include_path='.:/usr/share/php:/var/www/html/'
but it's not working!
Edit: in my libraries folder I have file called index.php the content is:
<?php
header("Location: ../"); die();
I wouldn't leave library paths to chance like that:
require_once(__DIR__ . '/libraries/Stripe/init.php');
This would make sure you include the script using the absolute directory path of the currently running script.
Update
Failed opening required '/var/www/html/libraries/Stripe/init.php'
Well, then the file is simply not there; if this file was generated by some other tool, e.g. composer, it would need to be done again on a new server (or ideally at every deployment).
i think the problem is my Stripe folder is in "s" but I'm using capital "S". is there anyway to make not case sensitive?
File systems under Linux are case sensitive by default (not even sure whether it can be changed) as opposed to Windows. Make sure you use capitalisation consistently.
That not what you are looking for. it says that php.ini file can't find the path of the file that you specified. that's why you should use absolute path to the file
require_once "path/to/file";

Include Path issue with config and header

I have a problem with include path in PHP.
Code:
https://github.com/kukubaczek/KukuShop/blob/master/www/panel/index.php
If i open the panel/index.php page I see this error's:
Warning: require_once(/parts/header.php): failed to open stream: No
such file or directory in /PATH/KukuShop/www/panel/index.php on line 3
Fatal error: require_once(): Failed opening required
'/parts/header.php' (include_path='/..') in
/PATH/KukuShop/www/panel/index.php on line 3
How can I fix this? Here is problem with include path.
You are using absolute references when you probably want relative file locations. Try using this instead:
require_once("../parts/header.php")
What does the directory structure look like?
The set_include_path('/..'); statement doesn't seem to make sense.
Your PHP installation can't seem to find the files.

Symlink - require_once doesn't seem to work?

I store my WordPress theme in my Dropbox to use it easily on many machines. Unfortunately require_once()/include_once() doesn't seem to work for me.
Is store original theme at G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\
The symlink is placed at C:\xampp\htdocs\blabla\wp-content\themes\Blabla
When I wanted to require/include any file, eg. C:\xampp\htdocs\blabla\wp-load.php I used to do require_once('../../wp-load.php');
But with symlink all I got is:
Warning: require_once(../../../wp-load.php): failed to
open stream: No such file or directory in
G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\foo\bar.php on line
2 Fatal error: require_once(): Failed
opening required '../../../wp-load.php'
(include_path='.;C:\xampp\php\PEAR') in
G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\foo\bar.php on line
2
Looks like require_once looks for the file within the Dropbox, not symlink context? Is it possible to fix it somehow? I can't use absolute path as I develop on different machines / different OSes and those vary... Any ideas? How does require_once work when it's symlinked? Does it look for required file in both places (original-context & symlink-context)?
How about putting the original file into you Wordpress folder and symlinking to dropbox?
While installing this, you should turn off dropbox on all machines where you did not move the folder yet.

php require not working after load() method to refresh a div

I have inside my div a php require to
require('inc/coreturni/list.php');
that requires again a db connection
require('inc/connect.inc.php');
and they both work when I load the page.
but if I try to refresh the div, by refreshing the first include file after a click event, with jquery load()
I got the following path error:
Warning: require(inc/connect.inc.php): failed to open stream: No such file or directory in C:\xampp\htdocs\taximat\inc\coreturni\list.inc.php on line 2
Fatal error: require(): Failed opening required 'inc/connect.inc.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\taximat\inc\coreturni\list.inc.php on line 2
why the path should be different? how could i fix it?
Your error explains it all:
Warning: require(inc/connect.inc.php): failed to open stream: No such
file or directory in
C:\xampp\htdocs\taximat\inc\coreturni\list.inc.php on line 2
Fatal error: require(): Failed opening required 'inc/connect.inc.php'
(include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\taximat\inc\coreturni\list.inc.php on line 2
Notice how it says it can’t find inc/connect.inc.php in this directory:
C:\xampp\htdocs\taximat\inc\coreturni
It’s because your require statements are referring to relative paths. So when the file list.inc.php is loaded, the require is assuming that inc/connect.inc.php is located in C:\xampp\htdocs\taximat\inc\coreturni. Which is why it is failing.
You should set a base path in your app like so. Just a note that I am unclear on forward-slash or back-slash syntax in a case like this since I work mainly on Mac & Unix systems and the error shows windows paths, but the PHP is showing Unix paths.
$BASE_PATH='/xampp/htdocs/taximat/inc/coreturni/';
And the require all files like this:
require($BASE_PATH . 'inc/coreturni/list.php');
And like this:
require($BASE_PATH . 'inc/connect.inc.php');
That way no matter where the files are called from, the require will use an absolute path to the file. And since $BASE_PATH is a one-time variable you set you can just set it in your main config file and not worry about it. To make the code portable, just change $BASE_PATH based on system setups.
When the page is displayed for the first time, your paths are like this:
page.php
inc/
coreturni/
list.php
connect.php
In other words, all require statements will be relative as seen from page.php.
However, when you request list.php directly using AJAX, it looks more like this:
list.php
../
connect.php
Now, the require should have been for ../connect.php.
Solution
One way to solve this is by calculating the absolute path based on the file currently being processed (i.e. list.php) like this:
require dirname(__DIR__) . '/connect.php';
The dirname(__DIR__) construct will always yield the directory on your file system that's one higher up than the current script is in.

Warning and Fatal error calling require_once()

I want to fetch div element from other website .
on which iam having my profile, i have tried using this code.
require_once('../simple_html_dom.php');
$html=file_get_html('http://www.example.com');
$ret=$html->find("div[id=frame-gallery]");
$ret=array_shift($ret);
echo($ret);
but this code is giving errors
Warning:
require_once(../simple_html_dom.php)
[function.require-once]: failed to
open stream: No such file or directory
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
Fatal error: require_once()
[function.require]: Failed opening
required '../simple_html_dom.php'
(include_path='.;./includes;./pear')
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
iam stuck with this plz help me with the code snippets for fetching the specific div element from a website
The file simple_html_dom.php is not where you're telling PHP to look for it.
require_once('../simple_html_dom.php');
To be safe, try using the full path instead of a relative path.
require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
BTW, if the full path above is incorrect, then that is your problem. This is the path that PHP is trying.
To clarify: I'm only suggesting the OP switch to absolute paths to identify and confirm the source of the issue. Going to production with absolute paths is rarely a good idea.
require and include paths can be tricky in PHP. Try to use full paths when you can. You'll find $_SERVER['DOCUMENT_ROOT'] usefull for that.
Your inlude_path should contain ".", which means current directory.
But if you having troubles with including file by relative name, then just try to use absolute names, like require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
But better it should be:
require_once 'E:/wamp/www/in.com/components/simple_html_dom.php';

Categories