0
<?php
$title = $_POST['title'];
$filename = $title , ".php";
$fh = fopen($filename, 'w') or die ("can't open file");
$stringData = $title;
fwrite($fh, $stringData);
$stringData = $blog;
fwrite($fh, $stringData);
fclose($fh);
?>

This is only a sample. What is the correct code for that?

1
  • 1
    Correct code for what, exactly? You need to be more specific with your question. Commented Apr 16, 2010 at 17:51

2 Answers 2

1

You are using the correct code there, what is the point?

Also note that you are using a comma rather than a dot to concatenate strings at:

$filename = $title , ".php";
Sign up to request clarification or add additional context in comments.

3 Comments

This is the error shows if i use that code.... I don't know why but it says that the comma has an error... "Parse error: syntax error, unexpected ',' in C:\Program Files\xampp\htdocs\Jordan Pagaduan\blog_creator.php on line 11"
@Jordan: as Sarfraz said in his answer, concatenation is done with a ., not a ,. Swap the , for a . and it should work.
oh.... thank you so much... i didn't understand the answer of sarfraz.. thank you...
1

In your example opening a file using POST is an insecure method, so don't even think about this kinda tricks :P

You can use file read and write in simple method

file_get_contents();

echo $fileData = file_get_contents('filename.txt');

file_put_contents();

$data= 'some data';
// Write the contents back to the file
file_put_contents("filename.txt", $data);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.