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).
Related
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
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've seen similiar questions but the answers did not help me. I'm using the code below. I have checked, the file is being read and it will output the number in count.txt on the page. $hit_count is indeed being incremented (I echoed that for a test). count.txt has permissions 777 and count.txt is in the same directory as the page I want the data to appear on. I have no idea what to do next. It's incredibly simple code and I have searched for an answer for hours.
<?php
$hit_count = #file_get_contents('count.txt'); // read the hit count from file
echo "Site visits since Jun 30,2012: ";
echo $hit_count; // display the hit count
$hit_count++; // increment the hit count by 1
#file_put_contents('count.txt', $hit_count); // store the new hit count
?>
If I remove the # sign to test the error I get the following:
Warning: file_put_contents(count.txt) [function.file-put-contents]: failed to open stream: Permission denied in D:\Hosting\9541237\html\indexTEST.php on line 220
What permissions? count.txt is 777.
I would check to see what php thinks your file permissions are using fileperms.
See this question for more info.
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 want to create File that have Full permission dynamically, that means every change for ID of session create new file .
Unfortunately I faced some problem .
Warning: fopen(test.txt) [function.fopen]: failed to open stream: Permission denied in /home/teamroom/public_html/1/3.php on line 2
Warning: fwrite(): supplied argument is not a valid stream resource in /home/teamroom/public_html/1/3.php on line 3
Warning: fclose(): supplied argument is not a valid stream resource in /home/teamroom/public_html/1/3.php on line 4
code :
<?php
session();
$member_Id=$_SESSION['user_id'];
if (isset($member_Id)){
$file = fopen("test.txt","x+");
fwrite($file,"test");
fclose($file);
}
?>
can you help me ?
or can you tell another way to do this idea ?
It would appear that the process PHP is running as (often the web server, e.g. www-data) does not have write permissions for the folder you're trying to create the file in
(e.g. /home/teamroom/public_html/1/).
You also should be doing error checking on the fopen() call. Then there's the security assect to think of.
you have no permissions to access directory. Use php-function chmod ("/somedir/somefile", 755); or change directory permissions by ftp-client.
And why are you trying to open file with x+ if you need only writing:
Modes:
r - Reading only, beginning of file
r+ - Reading and writing, beginning of file
w - Writing only, beginning of file
w+ - Writing and reading, beginning of file
a - Writing only, end of file
a+ - Writing and reading, end of file
x - Create and open for writing only, beginning of file
x+ - Create and open for reading and writing, beginning of file
If the file does not exist and you use w, w+, a or a+ it will attempt to create the file.
I think you can use w+ or a+
And for your another problem:
<?php
$fp = fopen ('/path/to/file', "r");
while (!feof ($fp))
{
$value = fgets($fp);
if(!empty($value))
{
//Here do what you want with your value
}
}
?>
This was string-by-string reading code. Also you can use file_get_contents(); php-function and work with it lika string.
P.S> Sorry for my english