

Include an error in writing the html file from php
source link: https://www.codesd.com/item/include-an-error-in-writing-the-html-file-from-php.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Include an error in writing the html file from php
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);
Recommend
-
9
Writing HTML with accessibility in mindAn introduction to web accessibility. Tips on how to improve your markup and provide users with more and betters ways to navigate and interact with your site.If you...
-
4
How to include a PHP file at the site level using .HTACCESS or other methods advertisements I want to include my PHP file googleanayltic...
-
5
If you’re going to configure a header file, you have to do it before you include the header file Raymond December 9th, 2021 ...
-
7
Tip: Include Context And Propose Solutions In Your Error Messages May 23, 2013 A Puppet run has failed with an error message...
-
6
The other day I encountered some issues with images for external sources not loading. I saved a link to someone's Twitter profile image in this case. When the user changes this image, it doesn't auto ref...
-
4
How to Include a JavaScript File in another JavaScript File 7968 views 2 years ago Javascript Use the
-
9
skyscraper's blog How to include...
-
6
Express Returns Servers HTML Error Page Instead of res.json Error MessageSkip to content
-
9
6 New ChatGPT Features Include Prompt Examples & File Uploads With GPT-4 as the new default, longer login duration, and suggested replies, these new ChatGPT...
-
4
Hexo blog title include special symbols reports error ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK