I get this error:
Warning: require_once(C:\xampp\htdocs/models/config.php): failed to open stream: No such file or directory in C:\xampp\htdocs\venture\html\admin\index.php on line 3
Here is the code where the error appears:
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require_once($root . "/models/config.php");
you need change slash
$root = realpath(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) );
require_once($root . "/models/config.php");
Related
I have been trying to switch my web app from localhost to a school server but it's telling me it cannot find the path:
Warning: require_once(/util/tags.php): failed to open stream: No such
file or directory in
/home/xiaoant/public_html/database_pizza/pizza/util/main.php on line
17
Fatal error: require_once(): Failed opening required '/util/tags.php'
(include_path='///') in
/home/xiaoant/public_html/database_pizza/pizza/util/main.php on line
17
<?php
// Start session to store user and cart data
session_start();
// Get the document root
$doc_root = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT', FILTER_SANITIZE_STRING);
// Get the application path
$uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING);
$dirs = explode('/', $uri);
$app_path = '/' . $dirs[1] . '/' . $dirs[2] . '/';
// Set the include path
set_include_path($doc_root . $app_path);
// Get common code
require_once('/util/tags.php');
require_once('/model/database.php');
// Define some common functions
function display_db_error($error_message) {
global $app_path;
include 'errors/db_error.php';
exit;
}
function display_error($error_message) {
global $app_path;
include 'errors/error.php';
exit;
}
?>
If you're using window and hosted it on a linux server Please check you path if it contain upper case letters directory names in linux is case sensitive unlike windows
Also you could list all the files in directory to check
'''$files1 = scandir($dir);
print_r($files1);
'''
And see if it there
I am trying to read a file from SFTP. I am able to connect to the server read information when I run the URL via browser.
But when I run this command from the command line I get many errors
This is the error that I get
C:\Users\test>php -f C:\phpsites\dp_in\IN_sales.php
PHP Warning: require(../classes/connection.php): failed to open stream: No such
file or directory in C:\phpsites\dp_in\IN_sales.php on line 17
Warning: require(../classes/connection.php): failed to open stream: No such file
or directory in C:\phpsites\dp_in\IN_sales.php on line 17
PHP Fatal error: require(): Failed opening required '../classes/connection.php'
(include_path='.;C:\php\pear') in C:\phpsites\dp_in\IN_sales.php on li
ne 17
Fatal error: require(): Failed opening required '../classes/connection.php' (inc
lude_path='.;C:\php\pear') in C:\phpsites\dp_in\IN_sales.php on line 17
This is how I connect to the server using SFTP.
$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
Another weird thing is that another file using similar code works with no issues!
I am not sure what could be causing this issue
EDITED
Here is my entire code after the edit
<?php
ini_set('max_execution_time', 900);
ini_set('user_ini.cache_ttl', 900);
date_default_timezone_set('America/Los_Angeles');
error_reporting(E_ALL);
ini_set('display_errors', 1);
$today = strtotime( "-25 day" );
$remote_file = '/per/Data_'. date('Ymd', $today ) . '.csv';
//set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include(__DIR__ . '/Net/SFTP.php');
//include "phpseclib.php";
$sftp = new Net_SFTP('IPADDRESS');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
if(empty($sftp->size($remote_file))){
exit('File Not Found - ' . $remote_file);
}
$csv = $sftp->get($remote_file);
$handle = fopen('php://temp', 'r+');
fputs($handle, $csv);
rewind($handle);
$data = array();
while ($csv_row = fgetcsv($handle) ) {
$data[] = $csv_row;
}
fclose($handle);
require realpath(__DIR__ . '/..') . '/classes/connection.php';
use __DIR__ in your require in order to require your files properly:
require(__DIR__ . "../classes/connection.php")
Multiple issues...
1) You need to define your includes path so that the require works
2) Your connection is probably failing because of #1 (missing credentials from included file)
I figured it out!!
I added this code to the top one my file
chdir(dirname(__FILE__));
This changes the working directory to the running file path.
This is working fine on init.php
include 'models/m_app.php';
include 'views/v_app.php';
include 'controllers/c_app.php';
but the spl_autoload_register() is not working
spl_autoload_register(function ($class) {
include 'models/' . $class . '.class.php';
include 'views/' . $class . '.class.php';
include 'controllers/' . $class . '.class.php';
});
and I am getting error like
Warning: include(models/Model.class.php): failed to open stream: No such file or directory in C:\wamp\www\App\core\init.php on line 3
Warning: include(): Failed opening 'models/Model.class.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\App\core\init.php on line 3
Warning: include(views/Model.class.php): failed to open stream: No such file or directory in C:\wamp\www\App\core\init.php on line 4
Warning: include(): Failed opening 'views/Model.class.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\App\core\init.php on line 4
Warning: include(controllers/Model.class.php): failed to open stream: No such file or directory in C:\wamp\www\App\core\init.php on line 5
Warning: include(): Failed opening 'controllers/Model.class.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\App\core\init.php on line 5
Can you please let me know why this is happening?
Well, you are using the spl_autoload_register function incorrectly.
An autoload function is getting called, when you are trying to create a class that does not exist.
The correct way would be to name your files just as the class inside them and add an ending like .class.php:
View.class.php
Model.class.php
Controller.class.php
The autoloader:
spl_autoload_register(function ($class) {
set_include_path('views/' . PATH_SEPARATOR . 'controllers/' . PATH_SEPARATOR . 'models/');
include $class . '.class.php';
});
And to test it:
$test1 = new Model();
$test2 = new Controller();
$test3 = new View();
Here is function that I'm using for recursively deleting folders and files
function rmdir_recursively($dir) {
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $file) {
if ($file == '.' || $file == '..') continue;
if (!rmdir_recursively($dir . DIRECTORY_SEPARATOR . $file)) {
chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
if (!rmdir_recursively($dir . DIRECTORY_SEPARATOR . $file)) return false;
};
}
return rmdir($dir);
}
The problem is, when I send some folder inside root, it deletes this folder. But when I send root folder itself like that
rmdir_recursively("./");
It returns bunch of errors like below
PHP Warning: unlink(.//wp/wp-admin/network) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-admin/user) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-content) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-content/plugins) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-content/plugins/akismet) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
What am I missing?
You say you're sending it rmdir_recursively("./");?
But look at the code, you are later calling rmdir_recursively($dir . DIRECTORY_SEPARATOR . $file).
This means that you'll be trying to eliminate files in ".//".
Which is why your error message contains unlink(.//wp/wp-admin/user)
Use rmdir_recursively("."); instead.
Error: [2] require_once(Zend/Loader/Autoloader.php) [function.require-once]: failed to open stream: No such file or directory
/var/www/vhosts/localhost/httpdocs/public.:./var/www/vhosts/localhost/httpdocs/public/../library:./var/www/vhosts/localhost/httpdocs/public/../model:.
defined('SITE_ROOT') ? null : define('SITE_ROOT',$_SERVER['DOCUMENT_ROOT']);
$includePath[] = '.';
$includePath[] = '.' . SITE_ROOT . '/../library';
$includePath[] = '.' . SITE_ROOT . '/../model';
$includePath[] = get_include_path();
$includePath = implode(PATH_SEPARATOR,$includePath);
set_include_path($includePath);
require_once 'Zend/Loader/Autoloader.php';
Please help me setting properly set_include_path.
You are using lines such as this :
$includePath[] = '.' . SITE_ROOT . '/../library';
Which get you an include_path such as this :
./var/www/vhosts/localhost/httpdocs/public/../library
Note the . at the beginning of that path -- I'm guessing it shouldn't be there.
Try removing thoses . at the beginning of each path :
$includePath[] = '.';
$includePath[] = SITE_ROOT . '/../library';
$includePath[] = SITE_ROOT . '/../model';
$includePath[] = get_include_path();
$includePath = implode(PATH_SEPARATOR,$includePath);
set_include_path($includePath);
For information : A . in a UNIX path means "current directory" ; and a / at the beginning of a path means "the root of the server".
So, a path such as ./var/www actually means "the www directory that is inside the var directory that is inside the current directory".
And you probably need something like "the www directory that's inside the var directory that's at the root of the server."