newb Posted October 15, 2006 Share Posted October 15, 2006 how do you make a file in php. like mkdir, is there a function for making files... Link to comment https://forums.phpfreaks.com/topic/23990-making-files/ Share on other sites More sharing options...
dymon Posted October 15, 2006 Share Posted October 15, 2006 Such a function is touch().Try this link: http://www.php.net/manual/en/function.touch.php Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-108988 Share on other sites More sharing options...
redbullmarky Posted October 15, 2006 Share Posted October 15, 2006 sure, touch will create a file if it doesnt exist, but its primary aim is to alter the date/time of a file.what you want to look at is [url=http://uk.php.net/fopen]fopen[/url] which is for both opening existing and creating new files. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109030 Share on other sites More sharing options...
newb Posted October 15, 2006 Author Share Posted October 15, 2006 thanks, fopen works perfect. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109091 Share on other sites More sharing options...
newb Posted October 15, 2006 Author Share Posted October 15, 2006 i have another problem. this could doesnt work anyone can help me??[code]<?php mkdir("$dir/modules/$_POST[title]", 0777); fopen("$dir/modules/$_POST[title]/index.php", 'w'); $somecontent = "<?phpif (realpath(__FILE__) == realpath($_SERVER[SCRIPT_FILENAME])) {header('Location: ../../index.php'); die(); } $query = $config->query("SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'"); $row = mysql_fetch_array($query); $data = $row[body]; echo $data; ?>"; if (is_writable("$dir/modules/$_POST[title]/index.php")) { if (!$handle = fopen("$dir/modules/$_POST[title]/index.php", 'a')) { echo "Cannot open file ($dir/modules/$_POST[title]/index.php)"; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($dir/modules/$_POST[title]/index.php)"; exit; } echo "Success, wrote ($somecontent) to file ($dir/modules/$_POST[title]/index.php)"; fclose($handle); } else { echo "The file $dir/modules/$_POST[title]/index.php is not writable"; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109095 Share on other sites More sharing options...
newb Posted October 15, 2006 Author Share Posted October 15, 2006 help1?!?! Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109110 Share on other sites More sharing options...
redbullmarky Posted October 15, 2006 Share Posted October 15, 2006 you'll need to be specific about what the script is/isnt doing. do you get errors? do you get anything output to the screen at all? as you're involving the database and the filesystem, each which can cause problems other than the PHP script alone, it's hard to tell just from looking at it... Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109125 Share on other sites More sharing options...
Barand Posted October 15, 2006 Share Posted October 15, 2006 Take a look at the code you posted in reply #4 above and pay attention to the color coding. Strings should be red, php functions blue. So if the red spills onto the function calls you have a " or a ' missing somewhere to close a string literal. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109129 Share on other sites More sharing options...
newb Posted October 15, 2006 Author Share Posted October 15, 2006 i dont get what ur saying someone help please not working. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109136 Share on other sites More sharing options...
Barand Posted October 15, 2006 Share Posted October 15, 2006 [pre] your string starts here | | $somecontent = "<?phpif (realpath(__FILE__) == realpath($_SERVER[SCRIPT_FILENAME])) {header('Location: ../../index.php'); die(); } $query = $config->query("SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'"); | | | and finishes here !!![/pre] Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109138 Share on other sites More sharing options...
redbullmarky Posted October 15, 2006 Share Posted October 15, 2006 on this line:[code]$query = $config->query("SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'");[/code]the first double quote is effectively closing the opening quote as pointed out by barand. if you want to enclose double quotes within double quotes, or single quotes within single quotes, you need to escape them. so the above line will become:[code] $query = $config->query(\"SELECT * FROM table_mod_page WHERE title = '$_GET[mod]'\");[/code]note the two backslashes \ i added. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109149 Share on other sites More sharing options...
newb Posted October 15, 2006 Author Share Posted October 15, 2006 OH OK THANK U SO MUCH REDBULL THATS ALL I NEEDED EVERYONE ELSE WASNT HELPING ME MUCH. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109167 Share on other sites More sharing options...
Barand Posted October 15, 2006 Share Posted October 15, 2006 Sorry, Newb. I didn't realise you still needed to be spoon-fed. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109201 Share on other sites More sharing options...
redbullmarky Posted October 15, 2006 Share Posted October 15, 2006 [quote author=Barand link=topic=111542.msg452269#msg452269 date=1160951397]Sorry, Newb. I didn't realise you still needed to be spoon-fed.[/quote] ;D ;Dno worries newb, however a tad unfair - i learnt many a thing from barand in the early days and the fact that he took the time to help (and actually gave you the solution, albeit in a different way) makes your comment a bit off. have a little more appreciation. Link to comment https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.