PHP can not find my class? - php

How can I specify the exact absolute path?
File is here. I specified it like this:
include "/home/core/public_html/d/core/source/class.Control.php";
Yet it tells me it is not.
*Fatal error: Class 'Control' not found in /home/core/public_html/d/core/source/class.ControlEntry.php on line *
Code:
<?php
class ControlEntry
{
private $control_object;
function __construct( $control_object )
{
$this->control_object = $control_object;
}
public function actuate()
{
if( isset($_POST['ajax_type']) )
{
$this->control_object->ajax( $_POST['ajax_type'] );
}
else
{
$this->control_object->reload();
}
}
}
include "/home/core/public_html/d/core/source/class.Control.php"; // Can not find this f***ing file even though it is there.
$control_entry_object = new ControlEntry( new Control() );
$control_entry_object->actuate();
Troubleshooting List

The error originates from class.ControlEntry.php. Make sure you load class.Control.php before you load ControlEntry.

That is the absolute path. It doesn't look like a bug. Actually it says the Class was not found. It doesn't say the file wasn't found. I guess in your class.ControlEntry.php line 3 references to Control. You need to include the file that contains control before using it.

You're including "/home/domain/public_html/d/core/source/class.Control.php"; but the error says /home/domain/public_html/d/core/source/class.ControlEntry.php. Are you sure you're including the right file or instantiating the right class?

Related

Include statement not working in PHP/Yii2

I have two files, the first one being in the main directory, console_output.php:
<?php
class console_output
{
function write_to_logfile($text) {
file_put_contents("log.txt", $text);
}
}
?>
and the second one in a subdirectory, xController.php
<?php
...import stuff...
include ("../console_output.php");
class xController extends Controller{
...do_stuff..
function doMoreStuff(){
...
$console_output = new console_output();
$console_output->write_to_logfile("did Stuff");
}
}
?>
This is all in Yii2 framework, in case that matters. I have tried with apps/console_output.php and ../console_output.php, but it fails either way.
When I use apps/console_output.php, the error is
include(app/console_output.php) [https://secure.php.net/manual/en/function.include.php'>function.include.php]: failed to open stream: No such file or directory
The error is shown right at the include statement.
Using ../console_output.php in the include statement gives me an error at
$console_output->write_to_logfile("did Stuff");
with the message
Class 'app\controllers\console_output' not found
I have no idea what I'm doing wrong here. Can you help me out please?
Yii(2) offers multiple shortcuts to various paths. The most commonly used one is
Yii::$app->urlManager->baseUrl
So You can include your php file like:
$url = Yii::$app->urlManager->baseUrl.'/../console_output.php';
include $url;
You relative path Def nation is wrong. You are using .. that mean you moving a director up from current script. You need to use "subdirectory/script.php"

PHP - Get class by included url

I want to getting class by included url between two hosts , I had to called class , there is a point which i have to creating an API , like a library to calling whatever. or it must be do by another way ?!
call.php
<?php
class call{
public function Call_Name($c = "") {
$c = "Called";
return $c;
}
}
?>
index.php
<?php
include 'http://example.com/new/call.php';
$call = new call();
echo $call->Call_Name();
?>
(allow_url_fopen , allow_url_include) is already on.
What you are looking for just isn't safe.
Instead of attempting to execute remote code, consider using a package manager such as Composer/Packagist. You can write your general classes once as a "library" and share them among your "packages".
Take a look here: https://getcomposer.org/ for how to get started.

how to allow transform in htmlpurifier

********* Updated question **************
So I have tried to implement my own AttrDef to HTMLPurifier but it doesn't "take", and I can't debug using die() either.
Here's what I have:
I created Transform.php in the HTMLPurifier/AttrDef/CSS/ directory. The only contents so far is this (I'm only trying to hook it in for now, I will add validating logics once I see that it is in the loop and thus can test it):
<?php
/**
* Validates Transform as defined by CSS.
*/
class HTMLPurifier_AttrDef_CSS_Transform extends HTMLPurifier_AttrDef
{
//basing this off of the color definition so the var is $color for now, may change it to $transform later
public function validate($color, $config, $context) {
return $color;
}
}
I added my file to library/HTMLPurifier.includes.php like this:
require 'HTMLPurifier/AttrDef/CSS/Transform.php';
and to the library/HTMLPurifier.safe-includes.php
require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Transform.php';
(not sure about the difference between these two include files above but all AttrDef files seemed to be in both so I added my file to both as well).
Then I try to make use of this new definition by adding this to library/HTMLPurifier/CSSDefinition.php:
// transform
$this->info['transform'] = new HTMLPurifier_AttrDef_CSS_Transform();
It is as if all of my additions were never made, and I can't debug it by putting a die() in my own file either, nothing happens.
So any advice on where I went wrong or how I can debug this is very much appreciated.
*********** addition *******
I also tried a simple bypass by applying the Color-AttrDef to any transform property, in the CSSDefinition.php:
$this->info['transform'] = new HTMLPurifier_AttrDef_CSS_Color();
And I hacked the original Color definition like this:
//TODO: testing ways to bypass
if (strpos($color, 'rotate(') !== false) {
return $color;
}
Not working. Please advice on what I am missing.
You'll need to define your own AttrDef which knows how to parse and validate such definitions. Color should serve as a decent model, since the rgb syntax is similar to matrix.

Unable to access library function in codeigniter

I am noob in codeigniter. I used an external class file for getting the length of an audio file. I put the file in application/libarary directory. After googling and reading documentation I tried two things for accessing the libarary function which I have mentioned under the codeigniter problem.
Working Demo from the External Library File
require ('classAudioFile.php');
$filename = "40f11852c2314cdf1d06308f07de3b1c.mp3";
$AF = new AudioFile;
$AF->loadFile($filename);
echo $AF->wave_length;
CodeIgniter Problem
$filename = "./uploads/audio_files/347f21502e9b27fac4707b07c3c15eb7.mp3";
$CI =& get_instance();
$CI->load->library('AudioFile');
$CI->AudioFile->loadFile($filename);
$filename = "./uploads/audio_files/347f21502e9b27fac4707b07c3c15eb7.mp3";
$this->load->library('AudioFile');
$this->AudioFile->loadFile($filename);
I am getting Call to a member function loadFile() on a non-object in D:\wamp\www\webcartz\application\modules\playlist\controllers\admin.php on line 149 this is the actuall error.. can any body please help. I tried to call it in both Controller and View file.
to normalize everything try the following:
the AudioFile.php you put in the library folder, make the file name all lower case, like audiofile.php. if it is called classAudioFile.php, rename it to simply audiofile.php
check that there is a class AudioFile in audiofile.php.
change the AudioFile in the load->library to all lowercase
change the AudioFile in the $this->AudioFile-> to all lowercase
if it still does not work change the name of the class (not the file) to Audiofile, capital A, lower case f.
Also, there should be an default - no parameter constructor in the class Audiofile. like this:
public function __construct()
{
// you can put some code here if you want
}

Code igniter third party, $this->load->add_package_path not working correctly

I am trying to use elliothaughins Socialize system for code igniter,
However I keep getting
Message: include(application/third_party/config/socializenetworks.php): failed to open stream: No such file or directory
I have traced this issue and when I call
$this->load->add_package_path(APPPATH.'third_party/socialize/');
In the loader class if I do die($path) I only get application/third_party.
It seems strange though as the code for the controller is
class SocializeController extends CI_Controller {
function __construct(){
parent::__construct();
parse_str($_SERVER['QUERY_STRING'], $_GET);
$this->load->add_package_path(APPPATH.'third_party/socialize/');
$this->_autoload();
}
private function _autoload(){
$this->load->model('socialize_migration_model');
$autoload = array();
include(APPPATH.'third_party/socialize/config/autoload'.EXT);
foreach ( $autoload as $type => $files ) {
$type = ($type == 'libraries') ? 'library' : $type;
foreach ( $files as $file ){
$this->load->$type($file);
}
}
}
public function data($key, $value)
{
$this->load->vars(array($key => $value));
}
}
Which as you can see it is calling a model, which it successfully loads,
It is when It gets to the autoloader where it loads the libraries where it breaks,
The particular library that is giving issue starts like
class SocializeNetworks {
private $_obj;
private $_networks = array();
function __construct(){
$this->_obj =& get_instance();
$this->_obj->load->config('socializenetworks'); // this is the line we die on :(
So,
Whats going on here and how can I fix it?
I traced this down to a bug just yesterday in the CI v2.0.2 code base. Essentially what is happening is you are adding an additional path to check for files in (which is correct) and the load method loops through each of the paths until it finds the file you are looking for.
If you output your CI object, you'll probably see that what you are looking for is there, but it's still failing.
In the file /codeigniter/core/Config.php where the load method is, for some reason, the $found=false; isn't reset on each iteration through the path loop, so if the path is found on the first run (as it was in my case) then $found is set to true, but then on subsequent runs, $found is still true, so it tries to include a non-existent file.
I solved this by moving the declaration for the $found variable to just below the start of the first foreach loop. This way it resets it each time. I reported the bug, so hopefully it will be addressed in subsequent versions.

Categories