开发者

PHP write file... need help

开发者 https://www.devze.com 2022-12-26 23:17 出处:网络
<?php $title = $_POST[\'title\']; $filename = $title , ".php"; $fh = fopen($filename, \'w\') or die ("can\'t open file");
<?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?


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";


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消