I have the following function on a button:
$(function() {
$("#submit").click(function(){
$.ajaxSetup({ cache: false });
$.ajax({
url:'crfile.php',
type:'GET',
});
};
It calls the following PHP file:
if (session_status() == PHP_SESSION_ACTIVE){
session_destroy();
}
session_start();
$extension = ".txt";
$_SESSION['fname'] = substr(md5(rand()), 0, 7).$extension;
fopen("temp/" . $_SESSION['fname'], 'w');
$fname = $_SESSION['fname'];
It creates a file with a random name in the temp/ folder. Both are working properly except when I click the #submit button a second time without reloading the page. It reruns the function, however it doesn't generate a new filename in the PHP script.
I thought it was cache or sessions, however neither is the case. I am using PHP 5.5.
Can someone please advise?