Jump to: navigation, search

PHP File Create

From w3cyberlearnings

Contents

PHP Create File

Create a file in PHP is simily write to a file that is not already existed.

Syntax fopen

  • w: write to a file
fopen(filename,'w');

Example 1

  • If the file myfirstfile.txt is not existed yet, it will create a new file.
<?php

$filename = "myfirstfile.txt";
$filehandle = fopen($filename, 'w') or die("can't open file");
fclose($filehandle);
?>

Example 2: create a list of a new file from an array

<?php

$aa_file_name = array('apple', 'banana', 'orange');
foreach ($aa_file_name as $filename) {
	$filehandle = fopen($filename . '.txt', 'w') or die("can't open file");
}
fclose($filehandle);
?>

Output: The following files are created

apple.txt banana.txt orange.txt

Related Links


  1. PHP File Linux vs. Windows
  2. PHP File Information
  3. PHP File Create
  4. PHP File Close
  5. PHP File Read
  6. PHP File Read Reverse
  1. PHP File Write
  2. PHP File Write to end or append to
  3. PHP File Write at Beginning
  4. PHP File Write at specific location
  5. PHP File Truncate
  6. PHP File Replace a specific word
  1. PHP File Replace a specific word with associative array
  2. PHP File Copy File
  3. PHP File Copy Reverse
  4. PHP File Search within file
  5. PHP File Delete File
  6. PHP File Template
  1. PHP File Email Template
  2. PHP File Template with MySQL
  3. PHP File Access with MySQL
Navigation
Web
SQL
MISC
References