Auto File Rename while Uploading – For Example: 00004001, 00004002, 0000400

I am new to PHP and I need some help in the below code. The below code is working fine but I need to add a "Functionality to be added in the below code, so that if any New File is uploaded it should auto increment in a series. For Example: 00004001, 00004002, 00004003.... and so on.

Please help...! Below is the existing code. Currently it Uploads the exact file name to the remote server.

<?php
if ( empty( $_FILES['file'] ) ) {
    return;
}
$ftp_server = "xx.xx.x.xxxx";
$ftp_user_name = "xxxxxxx";
$ftp_user_pass = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
$destination_file = "";
$source_file = $_FILES['file']['tmp_name'];

// set up basic connection
$conn_id = ftp_connect($ftp_server);


// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

//ftp_pasv($conn_id, true); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
    exit; 
}   else {


    echo "<p align=center> Your Image has been Uploaded if you dont't see any Error Msg Below</p> ";
}

// upload the file

$destination_folder = "/";
$destination_file = $destination_folder . "/" . basename($_FILES['file']['name']);
//ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

// check upload status
if (!$upload) { 


echo "<p align=center> **File Upload Has Failed &#128558</p> ";

} else {
echo "";
}

// close the FTP stream 
ftp_close($conn_id);
?>

PHP File Upload to FTP (Here Using Uploadify as FTP) — Unable to perform.

`Here is my HTML Code :

<html>
<head>
<title>Welcome</title>
</head>

<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile_1" type="file" /><br />
Choose a file to upload: <input name="uploadedfile_2" type="file" /><br />
<input type="submit" value="Upload Files" />
</form>
</body>
</html>

And Below is PHP :

<?php
$ftp_server = "94.xx.1.xxx";
$ftp_username   = "anxxxxxx";
$ftp_password   =  "xxxxxxxxx";

$conn_id = ftp_connect($ftp_server) or die("could not connect to $ftp_server");

if(@ftp_login($conn_id, $ftp_username, $ftp_password))
{
  echo "connected as $ftp_username@$ftp_server\n";
  }
else {
  echo "could not connect as $ftp_username\n";
}

$file = $_FILES["uploadedfile_1"]["name"];
$file2 = $_FILES["uploadedfile_2"]["name"];

$remote_file_path = "ansxxxx@94.xx.1.xxx/JustForTest".$file; // This is the Folder which I've created inside the FTP 
$remote_file_path2 = "ansxxxx@94.xx.1.xxx/JustForTest".$file2; // This is the Folder which I've created inside the FTP 

ftp_put($conn_id, $remote_file_path, $_FILES["uploadedfile_1"]["tmp_name"],FTP_ASCII);
ftp_put($conn_id, $remote_file_path2, $_FILES["uploadedfile_2"]["tmp_name"],FTP_ASCII);
ftp_close($conn_id);
echo "\n\nconnection closed";
?>


Error :

connected as anshu9453@94.23.1.139
Fatal error: Uncaught ValueError: Path cannot be empty in C:\xampp\htdocs\upload.php:22 Stack trace: #0 C:\xampp\htdocs\upload.php(22): ftp_put(Object(FTP\Connection), 'anshu9453@94.23...', '', 1) #1 {main} thrown in C:\xampp\htdocs\upload.php on line 22

It connects perfectly...but no files gets uploaded, throws the above error. I am new to php. PLEASE HELP...!

I would prefer to share the code, if anyone had done such kind of requirement.

Thanks a ton in Advance...!`