I have some problems with my project. In particular, I want to download file text with the name is the Date by code php. Can anyone have a suggestion or any idea?
@Suraj Here is my code. Specifically, I did create a text file that includes data that I store in my database. Then I want one more thing to be able to download this file with the name Date
<?php
$host = "localhost";
$dbuser = "id16877284_hoan";
$dbpass = "Dauhieubotu9@";
$db = "id16877284_admin";
date_default_timezone_set('Asia/Ho_Chi_Minh');
$conn = new mysqli($host,$dbuser,$dbpass, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);}
else { echo "Connected to mysql database. <br>"; }
if(!empty($_POST['sensor'])) {
$sensor = $_POST['sensor'];
$query = "INSERT INTO esp8266(sensor) values ('$sensor')";
$run = mysqli_query($conn,$query) or die (mysqli_error($conn));
$file = fopen(date("d-m-Y").".txt","a+");
fwrite($file,"sensor:");
fwrite($file,$sensor);
fwrite($file, date("d-m-Y H:i:s A")."\n");
echo "data will be saved"."\n";
if($run){
echo "form successful";
}
else {
echo "form failed";
}
}
?>