Jump to content

making files


newb

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.