Jump to content

Recommended Posts

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

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
https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109095
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
https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109125
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.
Link to comment
https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109129
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
https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109138
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
https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109149
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
https://forums.phpfreaks.com/topic/23990-making-files/#findComment-109202
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.