I've inherited a site from a developer and they're using the following function to set the document root and define the mysql_connection for the site I assume:
function construct()
{
$this->mysql_link = mysql_connect("the_host", "username", "password");
mysql_select_db("thedatabase", $this->mysql_link);
$this->rootDir = $_SERVER['DOCUMENT_ROOT']."admin/";
$this->templateDir = $this->rootDir."templates/";
$this->isAdmin();
}
The trouble is, when I try to run this on my local development platform (Mac OSX Lion/PHP/Mysql) I keep getting the following error:
Warning: include(/Library/WebServer/Documentsadmin/templates/index/In The News/item.php) [function.include]: failed to open stream: No such file or directory in /Users/mycomputername/Sites/thewebsite.com/admin/editable.class.php on line 283
I'm relatively new to PHP and I'm assuming there's a problem with my php.ini file pointing to the wrong place as the web root but I'm not sure how to fix that or if that's even the problem I'm experiencing.
The database connection is functioning properly though.
Any help in diagnosing this is greatly appreciated.
Why not set rootDir to
$this->rootDir = dirname(__FILE__)."/admin";
instead? (add some more dirname()s around it if you need a higher level).
Assuming of course that the rootDir you need is somehow related to this file.
Related
if i try the following command:
$_content = file_get_contents("ssh2.sftp://".intval($sftp)."/Lorem-62398848890105_20190117-101229.txt");
it works and i get the correct content.
But whenever I want to have all the files of the remote folder, the directory can not be opened.
I tried scandir or opendir. Both of these raises this message:
Warning: scandir(): Unable to open ssh2.sftp://12/ on remote host
What im doing wrong? Some tips would really help me.
Regards
Context: I use PHP 7.0.32 and ssh2.so is fully installed
UPDATE: I got it. I think it is due to a wrong attitude of the provider.
How it works:
$handle = opendir("ssh2.sftp://".intval($sftp).ssh2_sftp_realpath($sftp,".").'./');
The function ssh2_sftp_realpath + './' do the trick.
I am new to PHP, so I apologize for my inexperience. I am working in a Windows 10 environment and have installed WAMP to serve Apache, PHP, and MySQL. I am creating some remoteObject webservices for an Adobe AIR app that will communicate with Zend using AMF, and I have created an index.php file to get everything in motion, but when I browse to the index.php file, I get all kinds of errors. Here is the index.php file:
index.php
<?php
require_once('Zend/Amf/Server.php');
require_once('HalfService.php');
$server = new Zend_Amf_Server();
//adding our class to Zend AMF Server
$server->setClass("HalfService");
//Mapping the ActionScript VO to the PHP VO
//you don't have to add the package name
$server->setClassMap("VOService", "VOService");
echo($server -> handle());
?>
My File structure is:
C:/wamp64/www/
ZendFramework/library/Zend/Amf/Server.php
zendamf_remote/index.php
HalfService.php
VOService.php
I tried to create a include_path in my php.ini file that looks like this, but it did not work:
include_path = “c:\wamp64\www\ZendFramework\library”
Finally, this is the error that I get when I browse to index.php in a browser:
( ! ) Warning: require_once(Zend/Amf/Server.php): failed to open stream: No such file or directory in C:\wamp64\www\zendamf_remote\index.php on line 2
( ! ) Fatal error: require_once(): Failed opening required 'Zend/Amf/Server.php' (include_path='�c:\wamp64\www\ZendFramework\library�') in C:\wamp64\www\zendamf_remote\index.php on line 2
Any help at all in getting this configured would really be appreciated. Thanks so much!
"In your question you appear to have smart quotes around the path, so that may be it. See if changing that helps. – Tim Fountain"
Thanks to Tim Fountain for answering this question, who noticed something I wouldn't have seen in a million years
I am running Vagrant locally on my Windows PC, Vagrant is running CentOS and having a weird issue with something working fine locally on my Vagrant box, but getting a 500 error when pushing the code to my staging server.
Within my admin I have the following URL which grabs the id from the URL and uses that within a function to add some rows to a particular database table.
http://www.mysite.co.uk.192.168.0.155.xip.io/admin/settings/bulkclassroom/id/19312
This URL above in turn goes to my 'Settings' Controller and runs the follow function
public function actionBulkclassroom($id = null)
{
if (isset($id)) {
$model = new OrganisationClassroom();
$model->bulkAssignTeacherAllClassrooms($id);
}
}
This in turn uses the 'OrganisationClassroom' model and uses the following function to assign a teacher to all classrooms.
public function bulkAssignTeacherAllClassrooms($user_id = null)
{
if (!$user_id) return false;
$classes = OrganisationClassroom::model()->currentUserOrganisation()->findAll();
OrganisationClassroomsTeachersPivot::model()->deleteAll('user_id =:user_id ', array(':user_id'=> $user_id));
foreach($classes as $class)
{
$pivot = new OrganisationClassroomsTeachersPivot();
$pivot->classroom_id = $class->classroom_id;
$pivot->user_id = $user_id;
$pivot->save(false);
}
}
The code is pretty much self-explanatory and is working as expected when I run the code locally on my Vagrant box, however when I push the code to my staging server online I get the following error.
include(user_id.php) [function.include]: failed to open stream: No such file or directory
I am unsure why this is happening, nowhere in my code do I have an include(user_id.php) (I have done a search to double-check)
As the code & database tables are the same the issue can only be somehow related to my staging server setup somehow - can anyone suggest what is going on with this & how I can fix it?
For the record - this works 100% locally on my Vagrant box - it only gives the error on my staging server (has the same code & database structure) - the really odd thing is there is nowhere in my site do I have any includes referencing a file called user_id.php (I have double checked and there is definitely NO file called user_id.php on my local or remote staging server.
Any ideas?
check your file points to correct location that you have specified, mainly issue is with incorrect path to your file.
I've spent a lot of time troubleshooting this myself but none of what I've read solves my issue so I'm hoping I get some help here.
So anyway, I have written a PHP script that provides various functions to connect with Google Calendar. When I run this script directly using some inline test code to call my functions, everything runs fine. However, when I call the function from other scripts using 'require_once' to include it I get the following errors:
Warning: include_once(Zend\Gdata\Calendar\Extension\EventQuery.php) [function.include-once]: failed to open stream: No such file or directory in C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib\Zend\Loader.php on line 134
Warning: include_once() [function.include]: Failed opening 'Zend\Gdata\Calendar\Extension\EventQuery.php' for inclusion (include_path='.;C:\xampp\php\PEAR;C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib;C:\xampp\htdocs\TiersForTea.com\lib') in C:\Users\Luke Franklin\Clients\Tiers For Tea\Development\TiersForTea.com v1.1\lib\Zend\Loader.php on line 134
Your first thoughts might be that I'm not using the correct include path, but I have checked and rechecked this many times. I even tried hard coding the path. I'm quite sure that I'm using the correct path.
Now for the weird bit. If you look at the error you will notice the file Zend is trying to include: Zend\Gdata\Calendar\Extension\EventQuery.php. This file does not actually exist in the 'Extension' folder. It does exist in the parent folder though. If I just copy 'EventQuery.php' into the 'Extension' folder my script runs as expected. Weird, right?
So that does sorta solve my problem, but I would like to know what's going on here in-case it creates further issues. I should also note that I'm calling this script into an OpenCart module.
You might want to see some of my code so here's a snippet of the important bits, if you want more details just let me know:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath('\\lib') . PATH_SEPARATOR . "C:\\xampp\\htdocs\\TiersForTea.com\\lib");
require_once('Zend/Loader.php');
function connect() {
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
I doubt the error exists in any of the Zend files as you have indicated it works correctly in your isolation tests.
The error is thrown from Zend_Loader which means something in your code is making reference to Zend_Gdata_Calendar_Extension_EventQuery.
Check the stack trace for the error if available to pinpoint the location. If that's not available, do a global find for that string. If you find any matches, you will need to change them to Zend_Gdata_Calendar_EventQuery.
Update
Seems this is a known bug(s)
http://framework.zend.com/issues/browse/ZF-7013
http://framework.zend.com/issues/browse/ZF-11959
It's an issue when your code registers an error handler using ErrorException. Apparently it's fixed in the 1.12 branch but hasn't made it to a release yet.
There's a patch in the 11959 bug report that fixes the issue
UPDATED
My latest code as follows:
$file ="sqlite:C:\New folder\\test.db";
echo $file;
$handle = new PDO($file) or die("Could not open database");
Error
sqlite:C:\New folder est.db
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php:20 Stack trace: #0 C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php(20): PDO->__construct('sqlite:C:\New f...') #1 {main} thrown in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php on line 20
I'm trying to use PDO driver however the error keep prompting me saying cant find the driver when it's in my extension php folder. I'm at my wits now.
I'm using SQLITE version 3 and PHP version 5.4.3.
I already placed the database file inside my r/w folder but it Fatal error: Call to undefined function sqlite_open(). I already researched on the web for alot of sources but the my directory path still returns some strange error (Sorry if i'm too noob, first time learning).
My code as follows:
$db ="C:\New folder\test.db";
Test to print my directory path of the database.
echo $db;
$handle = sqlite_open($db); //or die("Could not open database");
Debug result
C:\New folder est.db
Fatal error: Call to undefined function sqlite_open() in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php on line 18 which is "$handle = sqlite_open($db); //or die("Could not open database");"
Kindly advise where did I do wrong? The path I specified was correct but when I print out, it shows wrong path.
Thanks
one problem you have is that you are escaping (inadvertently) some of your path characters.
As your var_dump shows.
C:\New folder est.db
change your $db variable definition to
$db ="C:\New folder\\test.db";
or just put path in single quotes so PHP won't try and parse the string
$db ='C:\New folder\test.db';
and believe it or not in most cases unix paths will work:
$db ="C:/New folder/test.db";
as for the remainder of your problem, you need to make sure you have sqlite 2 enabled. View your php info and check to see if you a section like:
SQLite
SQLite support enabled
PECL Module version 2.0-dev $Id: sqlite.c 306939 2011-01-01 02:19:59Z felipe $
SQLite Library 2.8.17
SQLite Encoding iso8859
if not, in your php.ini make sure the line
extension=php_sqlite.dll
is uncommented and present (and the .dll exists in your extension folder).
However most people will recommend that you use the PDO driver for sqlite (and for any other database) as it will provide a more consistent paradigm across the different databases (you can use the same code with most databases).
[edit]
I found some comments in the php manual that may shed some light on your issues.
It seems that the directory that contains your sqlite database must be
writeable by the web server. Making just the file writeable won't
work.
and
Don't forget "extension=php_pdo_sqlite.dll" has to be enabled in
php.ini (if you use xampp is will be disabled by default) .