I wrote the php code and the code to be loaded using curl, but every time I upload it to the server, it loads it with a .tmp extension and a different name. What is the reason for this?
PHP Code
<?php
if (isset($_POST['submit'])) {
$dataFile = $_FILES['srcfile']['tmp_name'];
$sftpServer = 'server_ip';
$sftpUsername = 'root';
$sftpPassword = 'password';
$sftpPort = 22;
$sftpRemoteDir = '/root';
$ch = curl_init('sftp://' . $sftpServer . ':' . $sftpPort . $sftpRemoteDir . '/' . basename($dataFile));
$fh = fopen($dataFile, 'r');
if ($fh) {
curl_setopt($ch, CURLOPT_USERPWD, $sftpUsername . ':' . $sftpPassword);
curl_setopt($ch, CURLOPT_UPLOAD, true);
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($dataFile));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataFile);
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($response) {
echo "Success";
} else {
echo "Failure";
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:\n" . $verboseLog . "\n";
}
}
}
?>
HTML CODE
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<br />
<div class="container">
<div class="col-xs-8 col-xs-offset-2 well" style="background:none;">
<form action="ftp_upload.php" method="post" enctype="multipart/form-data">
<legend>Please Choose File to Upload</legend>
<div class="form-group">
<input type="file" name="srcfile" />
</div>
<div class="form-group">
<input type="submit" name="submit" value="Upload File to FTP Server" class="btn btn-warning" />
</div>
</form>
</div>
</div>
</body>
</html>
The files I try to upload to my server are also uploaded with this figure .tmp extension and a random name. The php version I use is php8 xampp