I know how to save the sent texts in 1 text file created beforehand. but I need some way to save each text in separate text files which are created automatically
Asked
Active
Viewed 38 times
3
-
1Since you know how to write in a file, what stops you from writting in different files ? – Cid Jun 07 '19 at 11:04
-
I need the files to be generated automatically and i dont know how to do that.i only know how to write in a file which is created beforehand – Navid Hosseini Jun 07 '19 at 11:13
-
1Opening a file for writting/appending will create the file if it doesn't exist. This is stated in the documentation of [`fopen()`](https://www.php.net/manual/en/function.fopen.php) and [`file_put_contents()`](https://www.php.net/manual/en/function.file-put-contents.php) – Cid Jun 07 '19 at 11:15
2 Answers
0
The code below will save the text, which was provided by the user via GET parameter named param
, to a new file with unique name in form of hash (something like 6cc50baac239a47e165a320d03c76731.txt
).
<?php
$text = $_GET['param'];
file_put_contents(md5(uniqid(rand(), true)) . '.txt', $text);

Dejv
- 944
- 2
- 14
- 31
0
You can use fopen
to create a file, but before using that, read following PHP Manual
to find which mode is suitable for your case. Have a look in A list of possible modes for fopen() using mode
section:
Be successful.

Abbas Afsharfarnia
- 201
- 1
- 6