Forum Moderators: coopster
I have a normal html file "index.html" and a folder called "Old" in the same folder as index.html.
I am trying to create a php file which will copy the contents of index.html when the php file is run and paste the contents into a new file it creates in the "old" folder (along with the date and time in the title)
The problem is, The index.html has an php run rss feed in it with server side php processing (through htaccess), so what I need the php file to do is to copy the output that a user would see, not the php in index.html! if that makes sense :)
Any ideas?
ob_start();
include "http://your-web-site/index.html";
$data=ob_get_contents();
ob_clean();
This code will execute any and every php code that is in your index.html as a normal user would see and then it would return the compiler page content in the variable $data;
Just use Filestream and create a file in "Old" Directory and put $data in your file.
Simple
once that code gets you content of that page in variable $data
the following code will put in any file as you define, provided that file has write access.
(I would not recommend to play with File Permissions unless you know what you are doing)
<?php
$filename = 'Old/test.html';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
Hey! That File write code is boring enough, isnt it.?
what about this? ;)
ob_start();
include "http://your-web-site/index.html";
$data=ob_get_contents();
ob_clean();
$timestamp=date('H-i-m-d-Y');
$filename = "old/$timestamp.html";
$fp = fopen($filename, "w");
fwrite($fp, $data);
fclose($fp);
//after the execution of last line content grabbed from that url would have been copied and stored into your file curent hour-minute-month-day-year.html
for example
old/12-33-6-6-2005.html
Thats it ! cheers
I couldnt find my code quickly so i picked up code from the following url for you.
[php.net...]
Just put in in a php file and give it path of your directory, it will print our list
( I didnt test it ) Please check the above url for some more codes for this too
<?php $myfiles=GetDirContents(dirname($_SERVER['DOCUMENT_ROOT']));
print_r ($myfiles);
?>
<?php
function GetDirContents($dir){
ini_set("max_execution_time",10);
if (!is_dir($dir)){die ("Fehler in Funktion GetDirContents: kein g?s Verzeichnis: $dir!");}
if ($root=@opendir($dir)){
while ($file=readdir($root)){
if($file=="." ¦¦ $file==".."){continue;}
if(is_dir($dir."/".$file)){
$files=array_merge($files,GetDirContents($dir."/".$file));
}else{
$files[]=$dir."/".$file;
}
}
}
return $files;
}
?>
Have Fun