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
Related
So the scenario is, I have an ecommerce site which involves users uploading files & details, the links to the files & the text of the details is saved into a text file. All this stuff is uploaded into a temporary folder.
The payment system I have integrated is Paypal. I have Paypal send a response to the IPN. In this file, I send some emails, but I also wish to move the files into a permanent folder and thus edit the links in the text file. But I can't seem to access the files properly.
This is my error codes:
file_get_contents( ../uploads/tmp/file/*FILE NAME HERE*.doc) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/*username here*/public_html/*name*/*dir*/ipn.php on line 103
PHP Warning: file_put_contents( ../uploads/tmp/file/*FILE NAME HERE*.doc) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in /home/*username here*/public_html/*name*/*dir*/ipn.php on line 103
PHP Warning: copy( ../uploads/tmp/file/*FILE NAME HERE*).doc) [<a href='function.copy'>function.copy</a>]: failed to open stream: No such file or directory in *link to ipn.php* on line 106
//This is my code
if ($key == 'Book File '){
$oldBookFileName = $result['Book File '];
$oldBookLink = str_replace('*BASE URL IS HERE*', '../',$oldBookFileName);
if (strpos($result['Book File '],'/tmp/') !== false) {
$newBookFileName = str_replace("/tmp/","/perm /",$oldBookFileName);
$newBookLink = str_replace('*BASE URL IS HERE*', '../',$newBookFileName);
}
//update file names in file & move files
//include ('updatefile.php');
file_put_contents($oldBookLink, str_replace($oldBookFileName, $newBookFileName, file_get_contents($oldBookLink)));
//copy/move files from tmp to perm
copy($oldBookLink, $newBookLink);
}
I've tried using the full path (www.example.com/dir/file.php) and using the relative path (../dir/file.php). Also, all the links are correct, I echo'ed them out in an email and they are correct.
Anyone know what Im doing wrong? Something totally retarded? Please help.
Thank you.
You likely have the relative path wrong. Try using realpath() to see what path PHP is actually using.
For the full path you need to use the path on the server, not the http URL. So something like /home/username/public_html/dir/filename.doc instead of www.example.com/dir/filename.doc
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
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
Erg. Starting in the past few days high tweet IDs (at least, it appears it's ID related, but I suppose it could be some recent change in the api returns) are breaking my code. At first I tried passing the ID as a string instead of an integer to this function, and I thought this worked, but in reality it was just the process of uploading the file from my end.
In short, a php script generates these function calls, and when it does so, they fail. If I download the php file the call is generated into, delete the server copy and re-upload the exact same file without changing it, it works fine. Does anyone know what could be causing this behavior?
Below is what I suspect to be the most important part of the individual files that are pulling the errors. Each of the files is named for a status ID (e.g. the below file is named 12058543656.php)
<?php
require "singlePost.php";
SinglePost(12058543656)
?>
Here's the code that writes the above files:
$postFileName = $single_post_id.".php";
if(!file_exists($postFileName)){
$created_at_full = date("l, F jS, Y", strtotime($postRow[postdate])-(18000));
$postFileHandle = fopen($postFileName, 'w+');
fwrite($postFileHandle, '<html>
<head>
<title><?php $thisTITLE = "escarp | A brief poem or short story by '.$authorname.' on '.$created_at_full.'"; echo $thisTITLE;?></title><META NAME="Description" CONTENT="This brief poem or short story, by '.$authorname.', was published on '.$created_at_full.'">
<?php include("head.php");?>
To receive other poems or short stories like this one from <a href=http://twitter.com/escarp>escarp</a> on your cellphone, <a href=http://twitter.com/signup>create</a> and/or <a href=http://twitter.com/devices>associate</a> a Twitter account with your cellphone</a>, follow <a href=http://twitter.com/escarp>us</a>, and turn device updates on.
<pre><?php
require "singlePost.php";
SinglePost("'.$single_post_id.'")
?>
</div></div></pre><?php include("foot.php");?>
</body>
</html>');
fclose($postFileHandle);}
$postcounter++;
}
I can post more if you don't see anything here, but there are several files involved and I'm trying to avoid dumping tons of irrelevant code.
Error:
Warning: include(head.php) [function.include]: failed to open stream: No such file or directory in /f2/escarp/public/12177797583.php on line 4
Warning: include(head.php) [function.include]: failed to open stream: No such file or directory in /f2/escarp/public/12177797583.php on line 4
Warning: include() [function.include]: Failed opening 'head.php' for inclusion (include_path='.:/nfsn/apps/php5/lib/php/:/nfsn/apps/php/lib/php/') in /f2/escarp/public/12177797583.php on line 4
To receive other poems or short stories like this one from escarp on your cellphone, create and/or associate a Twitter account with your cellphone, follow us, and turn device updates on.
Warning: require(singlePost.php) [function.require]: failed to open stream: No such file or directory in /f2/escarp/public/12177797583.php on line 7
Warning: require(singlePost.php) [function.require]: failed to open stream: No such file or directory in /f2/escarp/public/12177797583.php on line 7
Fatal error: require() [function.require]: Failed opening required 'singlePost.php' (include_path='.:/nfsn/apps/php5/lib/php/:/nfsn/apps/php/lib/php/') in /f2/escarp/public/12177797583.php on line 7
SinglePost()
<?php
function SinglePost($statusID) {
require "nicetime.php";
$db = sqlite_open("db.escarp");
$updates = sqlite_query($db, "SELECT * FROM posts WHERE postID = '$statusID'");
$row = sqlite_fetch_array($updates, SQLITE_ASSOC);
$id = $row[authorID];
$result = sqlite_query($db, "SELECT * FROM authors WHERE authorID = '$id'");
$row5 = sqlite_fetch_array($result, SQLITE_ASSOC);
$created_at_full = date("l, F jS, Y", strtotime($row[postdate])-(18000));
$created_at = nicetime($row[postdate]);
if($row5[url]==""){
$authorurl = '';
}
else{
/*I'm omitting a few pages of output code and associated regex*/
return;
}
?>
I doubt the high ID values are causing your problem (at least, not data-type related).
When PHP detects an integer overflow, it automatically converts the value to a float to prevent it. Therefore you can (somewhat) represent big numbers without any problems.
That being said, please make sure that the full path to the file do not exceed path length limitations of your file system and that the number of files in your folder doesn't exceed limitations either (for example, 65534 entries is the max for NTFS partitions).