prcollin Posted May 30, 2008 Share Posted May 30, 2008 $fp = fopen('userpages/' . $page_title . '.html', 'a'); is that the correct format for the function to pull a value($page_title) from a form in a .html file and create a directory with the form entry?? Getting this error but permissions are all right. Im guessing its not pulling hte value and substituting it for the entered value. So how would i go about doing that? View my post here to see all the relavent code http://www.phpfreaks.com/forums/index.php/topic,199546.0.html Warning: fopen(userpages/page_title.html) [function.fopen]: failed to open stream: No such file or directory in /home/findzer/public_html/userpages/createfile.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/ Share on other sites More sharing options...
wildteen88 Posted May 30, 2008 Share Posted May 30, 2008 The problem is probably not do with the code but is more likely to do with the file path used in fopen. That code is being ran from the /home/findzer/public_html/userpages directory in a file called createfile.php (as the error states). Now the path you use in fopen is userpages/what-ever-file.html, As this is a relative file path PHP will add your path onto the current working directory (path above) and so the path PHP will use to open the .html file will be: /home/findzer/public_html/userpages/userpages/what-ever-file.html Which is obviously wrong. I'd suggest you to use: $fp = fopen('./' . $page_title . '.html', 'a'); // OR $fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/userpages/' . $page_title . '.html', 'a'); Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553751 Share on other sites More sharing options...
craygo Posted May 30, 2008 Share Posted May 30, 2008 Looking at your error, your script is running from the userpages folder, no need to go there again. $fp = fopen($page_title . '.html', 'a'); Ray Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553752 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 The problem is probably not do with the code but is more likely to do with the file path used in fopen. That code is being ran from the /home/findzer/public_html/userpages directory in a file called createfile.php (as the error states). Now the path you use in fopen is userpages/what-ever-file.html, As this is a relative file path PHP will add your path onto the current working directory (path above) and so the path PHP will use to open the .html file will be: /home/findzer/public_html/userpages/userpages/what-ever-file.html Which is obviously wrong. I'd suggest you to use: $fp = fopen('./' . $page_title . '.html', 'a'); // OR $fp = fopen($_SERVER['DOCUMENT_ROOT'] . '/userpages/' . $page_title . '.html', 'a'); Great no more errors, but now i just get a blank page when i click submit and there is no new file in the directory. Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553760 Share on other sites More sharing options...
wildteen88 Posted May 30, 2008 Share Posted May 30, 2008 Is your error_reporting to set to E_ALL? PHP should display all error types and not a blank page if error_reporting is set to E_ALL. Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553766 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 Is your error_reporting to set to E_ALL? PHP should display all error types and not a blank page if error_reporting is set to E_ALL. There are actually no errors but when i added echo $page_title; it printed page_title when i submitted the form so does this mean that the variables are not being recognized and if so should I just put my php script at the bottom of the form or should i declare the variables some other way? Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553768 Share on other sites More sharing options...
wildteen88 Posted May 30, 2008 Share Posted May 30, 2008 Looking back at your original thread your script is not being instructed to output anything, thus you get a blank page when form is submited. As for no file being created then you you should add fclose($fp); at the bottom of your script before ?> in createfile.php Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553772 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 Looking back at your original thread your script is not being instructed to output anything, thus you get a blank page when form is submited. As for no file being created then you you should add fclose($fp); at the bottom of your script before ?> in createfile.php new code <?php /** * *This script posts the new file to the directory * * (c) copyright 2008 Time Vision Development */ $page_title = 'page_title'; $user_email = 'user_email'; $about_you = 'about_you'; $fp = fopen('./' . $page_title . '.html', 'a'); fwrite($fp, '<b>Email Address:</b>'); fwrite($fp, '<br>'); fwrite($fp, $_POST[$user_email]); fwrite($fp, '<br>'); fwrite($fp, '<br>'); fwrite($fp, '<b>About Me:</b>'); fwrite($fp, '<br>'); fwrite($fp, $_POST[$about_you]); fwrite($fp, '<br>'); fwrite($fp, '<br>'); fwrite($fp, '<hr height="5" width="100%">'); echo $page_title; echo $user_email; echo $about_you; fclose($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553774 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 this is what it displays when i click submit page_titleuser_emailabout_you and it doesnt create a new file in the directory?? Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553776 Share on other sites More sharing options...
wildteen88 Posted May 30, 2008 Share Posted May 30, 2008 Try: <?php if(isset($_POST['submit'])) { $path = $_SERVER['DOCUMENT_ROOT'] . '/userpages/'; $file_name = $_POST['page_title']; $file_contents = "<b>Email Address:</b> <br> {$_POST['user_email']} <br /> <br /> <b>About Me:</b> <br /> {$_POST['about_you']} <br /> <br /> <hr height=\"5\" width=\"100%\">"; // Let's make sure the file exists and is writable first. if (is_writable($path)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($path . $file_name, 'a')) { echo "Cannot open file $file_name"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $file_contents) === FALSE) { echo "Cannot write to file $file_name"; exit; } echo "Success, created $file_name"; fclose($handle); } else { echo "The file $path is not writable"; } } else { echo 'Form not submitted! $_POST contents:'; echo '<pre>' . print_r($_POST, true) . '</pre>'; } ?> This is will print messages at different stages. It should identify where your script is failing. Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553779 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 These files are being written to the directory on submit they are not already in the directory each time the form is submitted a new file is supposed to be created with the form elements as the content and the &page_title as the document name Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553785 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 ok i used your script and got this Form not submitted! $_POST contents: Array ( [user_email] => asdf [page_title] => asdf [about_you] => asdf ) Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553786 Share on other sites More sharing options...
wildteen88 Posted May 30, 2008 Share Posted May 30, 2008 Name your submit button submit and it'll work. Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553787 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 Name your submit button submit and it'll work. ok that worked and it created the file but how do i create an html not just a plain file. Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553802 Share on other sites More sharing options...
prcollin Posted May 30, 2008 Author Share Posted May 30, 2008 TOPIC SOLVED THANKS WILD it worked like a dream. Quote Link to comment https://forums.phpfreaks.com/topic/108038-correct-format-or-no/#findComment-553813 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.