Jump to content

Create a html file dynamically


ramkarthik

Recommended Posts

Hi,

 

I want to create a .html file dynamically on the server. Below is the code for that but i was not able to create the file. I have given all the read, write and execute permission on  the folder.

 

$filerand = rand();

$fileName = "test.html";

$filepath = $_SERVER['DOCUMENT_ROOT'] . "\\testfolder\\" . $fileName . ".html";

echo $filepath;

 

$bodytxt = "Welcome to my webpage";

$ourFileHandle = fopen($filepath, 'w') or die("can't open file");

fwrite($ourFileHandle, $bodytxt);

fclose($ourFileHandle);

 

 

Thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/
Share on other sites

Are you sure? If it wouldn't be able to find the folder it would pop up with your 'can't open file' error. Are you recieving this error?

 

Oh I just spotted something,

 

$fileName = "test.html";
$filepath = $_SERVER['DOCUMENT_ROOT'] . "\\testfolder\\" . $fileName . ".html";

 

Your adding a second 'file extension' ... Try removing that.

May I ask why you're wanting to dynamically generate files? Usually when this question is asked, it's being attempted for all the wrong reasons . . .

 

I have PHP form, after entering all the details in that form, have a submit button. when clicking the submit button it will create a html file..

 

$fileName = "test.html";
$filepath = $_SERVER['DOCUMENT_ROOT'] . "\\testfolder\\" . $fileName . ".html";

 

Your adding a second 'file extension' ... Try removing that.

 

I have removed the second file extension also, but i am getting "can't open the file" error.

Haha dam what a bugger! I'm not sleeping till i figure this one out!

 

Anyone have any ideas?

 

I can only think that \t is an escape char of it's own... Could that be the cause?

 

I have given some other name also like "mailbackup", still i am getting the same error.

Well actually it seems to be working =/.. (Sorry had a mistake my side).

 

$_SERVER['DOCUMENT_ROOT'] returns the root folder of the server. Not the folder in which the script is working in...

 

The directory that it is echoing, try manually going to that directory?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.