找到你要的答案

Q:create php file from user input

Q:创建用户输入php文件

I need to create php file from user input using following code to create php file

<?php
    $my_file = 'newfile.php';
    $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); 
?>

above code creates new php file but i need to create file with some content

example I have two input

<input type="file" name="cover">
<input type="text" name="body">

php file should contain above input

I need to 创建用户输入php文件 using following code to create php file

<?php
    $my_file = 'newfile.php';
    $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); 
?>

以上代码创建新的PHP文件,但我需要一些内容创建文件

例子我有两个输入

<input type="file" name="cover">
<input type="text" name="body">

php文件应该包含上述输入

answer1: 回答1:

you have to write to file using fwrite. Try the following code.

fwrite($handle, 'Content form input 1');
fwrite($handle, 'content from input 2');
fclose($handle);

你必须使用fwrite写入文件。尝试以下代码。

fwrite($handle, 'Content form input 1');
fwrite($handle, 'content from input 2');
fclose($handle);
php