ted_chou12 Posted December 28, 2006 Share Posted December 28, 2006 I seem to find trouble both creating the folder itself and a file to store in it in the same page. The folder can be created, but the file doesnt seem to be stored into the folder... and you need a new page,(second page) for it to store the file in the folder, what may be the problem?Ted. Link to comment https://forums.phpfreaks.com/topic/32093-solved-create-a-folder-and-create-a-file-in-it-in-the-same-page/ Share on other sites More sharing options...
matto Posted December 29, 2006 Share Posted December 29, 2006 Can you post your code. :) Link to comment https://forums.phpfreaks.com/topic/32093-solved-create-a-folder-and-create-a-file-in-it-in-the-same-page/#findComment-149255 Share on other sites More sharing options...
wildteen88 Posted December 29, 2006 Share Posted December 29, 2006 When you go to create the folder. Keep the folder name in a variable. Then use that variable when creating the file. Example:[code]<?phpif(isset($_POST['submit'])){ $folder = $_POST['newFolder']; if(!file_exists($folder)) { if(!mkdir($folder)) { echo "Unable to create a new folder '$folder'"; } } $fileName = $_POST['newFileName']; $fileContents = $_POST['newFileContents']; $handle = fopen('./' . $folder . '/' . $fileName, 'wb'); fwrite($handle, $fileContents, strlen($fileContents)); fclose($handle); echo '<a href="./' . $folder . '/' . $fileName . '">' . $fileName . '</a> successfully crrated!';}?><h1>Create New File and Folder</h1><form action="" method="post"> Folder Name: <input type="text" name="newFolder" /><br /> File Name: <input type="text" name="newFileName" /><br /> File contents: <textarea name="newFileContents"></textarea><br /> <input type="submit" name="submit" value="Create!" /></form>[/code]Extremely basic. But it shows what I mean. Link to comment https://forums.phpfreaks.com/topic/32093-solved-create-a-folder-and-create-a-file-in-it-in-the-same-page/#findComment-149298 Share on other sites More sharing options...
ted_chou12 Posted December 29, 2006 Author Share Posted December 29, 2006 okay, thanks i understand. Link to comment https://forums.phpfreaks.com/topic/32093-solved-create-a-folder-and-create-a-file-in-it-in-the-same-page/#findComment-149300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.