Jump to content

Archived

This topic is now archived and is closed to further replies.

newb

making files

Recommended Posts

how do you make a file in php. like mkdir, is there a function for making files...

Share this post


Link to post
Share on other sites
Such a function is touch().

Try this link: http://www.php.net/manual/en/function.touch.php

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 = "<?php
if (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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
i dont get what ur saying someone help please not working.

Share this post


Link to post
Share on other sites
[pre]

                  your string starts here
                  |
                  |
$somecontent = "<?php
if (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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
OH OK THANK U SO MUCH REDBULL THATS ALL I NEEDED EVERYONE ELSE WASNT HELPING ME MUCH.

Share this post


Link to post
Share on other sites
[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 ;D
no 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.

Share this post


Link to post
Share on other sites

×

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.