Jump to content

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?

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.