ramkarthik Posted February 16, 2011 Share Posted February 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/ Share on other sites More sharing options...
cs.punk Posted February 16, 2011 Share Posted February 16, 2011 That code work's fine by me? Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175107 Share on other sites More sharing options...
ramkarthik Posted February 16, 2011 Author Share Posted February 16, 2011 That code work's fine by me? The file is creating on the server root directory.... But I was not able to create on a particular folder.... Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175123 Share on other sites More sharing options...
cs.punk Posted February 16, 2011 Share Posted February 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175129 Share on other sites More sharing options...
Pikachu2000 Posted February 16, 2011 Share Posted February 16, 2011 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 . . . Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175131 Share on other sites More sharing options...
ramkarthik Posted February 16, 2011 Author Share Posted February 16, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175133 Share on other sites More sharing options...
Jessica Posted February 16, 2011 Share Posted February 16, 2011 That doesn't really answer the question... I'd have to agree, it's probably for the wrong reasons. Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175134 Share on other sites More sharing options...
ramkarthik Posted February 16, 2011 Author Share Posted February 16, 2011 $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. Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175135 Share on other sites More sharing options...
cs.punk Posted February 16, 2011 Share Posted February 16, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175144 Share on other sites More sharing options...
ramkarthik Posted February 16, 2011 Author Share Posted February 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175146 Share on other sites More sharing options...
cs.punk Posted February 16, 2011 Share Posted February 16, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/227895-create-a-html-file-dynamically/#findComment-1175154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.