i have to fetch data from web page using phpquery and i have already used a example
this following is the code...
<?php
require_once(dirname(__FILE__) . "/phpQuery.php");
phpQuery::browserGet('http://www.google.com/', 'success1');
function success1($browser) {
$browser
->WebBrowser('success2')
->find('input[name=q]')
->val('search phrase')
->parents('form')
->submit();
}
function success2($browser) {
print $browser;
}
and right now i have a new error that is
Warning: require_once(WebBrowser.php): failed to open stream: No such file or directory in /var/www/TantraProjects/phpQuery/phpQuery.php on line 4922 Fatal error: require_once(): Failed opening required 'WebBrowser.php' (include_path='.:/usr/share/php:/usr/share/pear:/var/www/TantraProjects/phpQuery/phpQuery/:/var/www/TantraProjects/phpQuery/phpQuery/plugins/') in /var/www/TantraProjects/phpQuery/phpQuery.php on line 4922
i cant understand why this is shown , help me...
most obviously you don't have phpQuery.php in the same directory as you script - mind you: On a Linux webhost filenames are case-sensitive.
It's an additional file that needs to be available for reading.
The phpQuery WebBroswer is a plugin. Check that you have put that file (WebBrowser.php) into the location it gives you the error and that it's available to be read, e.g.
/var/www/TantraProjects/phpQuery/WebBroswer.php
Related
Good afternoon to everyone.
For the past 3 days, I've been struggling with PHP's Autoloading features, which aims to simplify and unify a program's class files, all located in one executing file. For the context, I am currently learning the OOP perspective of PHP from this tutorial videos to not only further understand PHP's OOP understanding before doing a PHP OOP project from college, but also to try to create my own PHP program, so do ELI5 about the solution to me, please.
From what I've learned from the following videos: Video 1 and Video 2, the autoload codes I written from what I've learned appears to work fine, however, it gave two warnings:
Warning: include(/classes/person.php): failed to open stream: No such file or directory in C:\xampp\htdocs\CollegeTimetableApp\includes\autoloader.php on line 12
Warning: include(): Failed opening '/classes/person.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\CollegeTimetableApp\includes\autoloader.php on line 12
And, it gave a fatal error message as follows:
Fatal error: Uncaught Error: Class 'person' not found in C:\xampp\htdocs\CollegeTimetableApp\includes\index.php:33 Stack trace: #0 {main} thrown in C:\xampp\htdocs\CollegeTimetableApp\includes\index.php on line 33
I will include downloadable files so that anyone check and verify it with me.
The Autoloader codes on the autoloading file:
<?php
spl_autoload_register(function($className) {
include str_replace("\\","/","\classes").'/'.str_replace('\\',"/",$className).'.php';
});
?>
Simple executing codes on the index file:
<?php
$person1 = new person();
$person1->SetName("Kai");
echo $person1->name;
?>
My questions: what's wrong, how to create a functioning autoload feature, and are there any additional corrections that can be made from my program?
Thank you.
Try including $_SERVER['DOCUMENT_ROOT'] to your path, as well as the sub folder in that folderwhich contains your app.
<?php
spl_autoload_register(function($className) {
$file = $_SERVER['DOCUMENT_ROOT']; // This is the folder you serve files from
$file .= '/CollegeTimetableApp' // This is the folder in which your app lives
$file .= str_replace("\\", "/", "\classes");
$file .= '/'; // Consider using DIRECTORY_SEPARATOR instead
$file .= str_replace('\\', "/", $className);
$file .= '.php';
include $file;
});
?>
I am having an issue.
OS - Windows 10
Developing Website on XAMPP v30204
Using PHP
Calling dynamic data from sql via link examples:
http://127.0.0.1/abbgi/category-page.php?category_id=73 - works, pulls all data from the SQL database and shows correctly via html in table.
http://127.0.0.1/abbgi/index.php?content=in-ground-basketball-goal-installation.php - works ( this is static content on a page withing main directory that shows correctly within the index.php content shell )
http://127.0.0.1/abbgi/index.php?content=category-page.php?category_id=88 - bad - ERROR:
Warning: include(category-page.php?category_id=88): failed to open stream: No such file or directory in C:\xampp\htdocs\abbgi\index.php on line 98
Warning: include(): Failed opening 'category-page.php?category_id=88' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\abbgi\index.php on line 98
Code on index.php:
<?php
if (!isset($_REQUEST['content']))
include("home.php");
else
{
$content = $_REQUEST['content'];
$nextpage = $content;
include($nextpage);
}
?>
It seems that when the link includes index.php pulling data from sql that it breaks.
Use & to separate data instead of ?
http://127.0.0.1/abbgi/index.php?content=category-page.php&category_id=88
You have used ? instead of & after content=category-page.php
I have a construct function where I am using include_path, the function looks like this :
public function __construct()
{
$url = $this->parseUrl();
if(file_exists('application\controllers'.$url[0].'.php')){
$this->controller=$url[0];
unset($url[0]);
}
require_once 'application\controllers'.$this->controller.'.php';
echo $this->controller;
}
Unfortunately, when I try to load an existing controller url like this one http://localhost/project/public_html/home I get the following error :
Warning: require_once(application\controllers home.php): failed to open stream: No such file or directory in C:\xampp\htdocs\project\application\core\App.php on line 24
Fatal error: require_once(): Failed opening required 'application\controllers home.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\project\application\core\App.php on line 24
I followed the documentation and I included the paths :
C:\xampp\htdocs\project\application
and
C:\xampp\htdocs\project\application\controllers
but I am still getting the error and I am just clueless why... can someone help me?
But you have a space in the path...is that normal?
Can you try with 'application\controllers' (without space there) please?
And controllershome.php is the name of file, or controllers/home.php?
Heres my code within functions.php:
<?php
$id = 10;
$html = file_get_contents("inc-star-rating.php?id=$id");
echo $html;
?>
Heres the contents of inc-star-rating.php:
<?php
$id = $_GET['id'];
echo "<div>I have the ID of $id</div>";
?>
They are both in the same directory on my server, so why am I getting the following error?:
Warning: file_get_contents(inc-star-rating.php?id=10)
[function.file-get-contents]: failed to open stream: No such file or
directory
inc-star-rating.php?id=10 is probably not the right file name. It probably does not exist like this in the filesystem.
If you mean to fetch a URL via an HTTP request, you need to explicitly give the full URL as it's accessible through the web server:
file_get_contents("http://localhost/inc-star-rating.php?id=$id")
Whether this is a good idea or not is a different topic though. Usually you want to require other PHP files and execute their code by calling functions in them, not make a new HTTP request.
I seem to have some problem with my code here. It creates a file from the php file, but I get an error on the include path.
include('../include/config.php');
$name = ($_GET['createname']) ? $_GET['createname'] : $_POST['createname'];
function buildhtml($strphpfile, $strhtmlfile) {
ob_start();
include($strphpfile);
$data = ob_get_contents();
$fp = fopen ($strhtmlfile, "w");
fwrite($fp, $data);
fclose($fp);
ob_end_clean();
}
buildhtml('portfolio.php?name='.$name, "../gallery/".$name.".html");
The problem seems to be here:
'portfolio.php?name='.$name
Any way I can replace this, and still send the variable over?
Here's the error I get when I put ?name after the php extension:
Warning: include(portfolio.php?name=hyundai) [function.include]: failed to open stream: No such file or directory in D:\Projects\Metro Web\Coding\admin\create.php on line 15
Warning: include(portfolio.php?name=hyundai) [function.include]: failed to open stream: No such file or directory in D:\Projects\Metro Web\Coding\admin\create.php on line 15
Warning: include() [function.include]: Failed opening 'portfolio.php?name=hyundai' for inclusion (include_path='.;C:\php\pear') in D:\Projects\Metro Web\Coding\admin\create.php on line 15
Now I saw your code in the comment to a previous answer I'd like to point few things out
function buildhtml($strhtmlfile) {
ob_start(); // redundant
$fp = fopen ($strhtmlfile, "w"); // redundant
file_put_contents($strhtmlfile,
file_get_contents("http://host/portfolio.php?name={$name}"));
// where does $name come from?? ---^
close($fp); // also redundant
ob_end_clean(); // also redundant
}
buildhtml('../gallery/'.$name.'.html');
In PHP as in many other languages you can do things in different ways. What you've done is you took three different ways and followed only one (which is absolutely enough). So when you use functions file_put_contents() and file_get_contents() you don't need the buffer, that is the ob_ family of functions, because you never read anything in the buffer which you should then get with ob_get_contents(). Nor you need the file handles created and used by fopen(), fclose(), because you've never written to or read from the file handle i.e. with fwrite() or fread().
If I'm guessing correctly that the purpose of your function is to copy html pages to local files, my proposal would be the following:
function buildhtml($dest_path, $name) {
file_put_contents($dest_path,
file_get_contents("http://host/portfolio.php?name={$name}"));
}
buildhtml('../gallery/'.$name.'.html', $name);
file_put_contents($strhtmlfile, file_get_contents("http://host/portfolio.php?name={$name}"))
Is it ok?
The output of:
'portfolio.php?name='.$name, "../gallery/".$name.".html";
is:
portfolio.php?name=[your name]../gallery/[your name].html
Are you sure that's what you want ?
include/require statements in PHP allow you to access the code contained in a file which is already stored on the server
What you are trying to achieve is including the output result of executing the code in that file with specific parameters
The suggested example offered by MrSil allows you to request the execution of the code in those files and offer parameters. The reason it shows you a blank page is because file_put_contents 'saves data to a file' and file_get_contents does not echo the result, it returns it. Remove the file_put_contents call, and add an echo at the beginning of the line before file_get_contents and it should work.
echo file_get_contents('http://domain.com/file.php?param=1');
As a warning this approach forces the execution of 2 separate PHP processes. An include would have executed the code of the second file within the first process.
To make the include approach work you need to include the file as you first did but without specifying parameters. Before including each file you need to setup the parameters it is expecting such as $_GET['name'] = $name