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
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.

Link to comment
Share on other sites

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..

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.