The following code shows an Example of Creating a File in PHP.
createfile.php
Here we write code to accept user input in a textarea. When user clicks on the submit button, writefile.php executes.
<form name="f1" method="POST" action="writefile.php">
Create a File:<br/>
<textarea rows="10" cols="100" name="t1">Enter content of file....</textarea>
<br/><br/>
<input type="submit" value="Create File"/>
</form>
writefile.php
Here, first we fetch the data using the POST variable. After that, the fopen() function opens the file in write mode. Further, the fwrite() function writes the data. Finally, the fclose() function closes the file.
<?php
echo '<h1>Example of creating file in PHP</h1>';
$filedata=$_POST['t1'];
$filename='myfile.txt';
$file1=fopen($filename,'w');
fwrite($file1,$filedata);
fclose($file1);
?>
Output



Further Reading
Examples of Array Functions in PHP
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML