0
I’m trying to move files from a folder. These files are listed, from the moment they are created, I want to move them at the end of the day to a certain back-up folder. However, when calling Function PHP responsible for this, nothing does.
Follow the code below:
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="50000">
<title></title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
function moveFile(fileName) {
$.ajax({
url:'copyFile.php',
type: "GET",
complete: function (fileName) {
alert("Arquivo foi movido!");
},
error: function () {
alert('Erro');
}
});
return false;
}
</script>
</head>
</head>
<body>
<?php
if(isset($_GET['path']))
$dir = $_GET['path'];
else
$dir = 'fileInfo/';
foreach (new DirectoryIterator($dir) as $file) {
if (!$file->isDot()) {
if ($file->isDir()) {
echo '<div>';
echo '<a href="index.php?path='.$dir. DIRECTORY_SEPARATOR .$file.'"></a><br/>' . $file->getBaseName();
echo '</div>';
} else {
switch($file->getExtension()) {
case 'txt':
echo "<a href='".$dir.$file."'>".$file."</a>" ?> <button onclick="moveFile('<?php echo $file?>')">Mover arquivo</button>
<?php
break;
}
}
}
}
?>
PHP that contains the function to transfer files:
<?php
function moverArquivos($file){
var_dump($file);
$dir = 'files/'.$file;
$destino = 'files/backup/';
copy($dir, $destino);
unlink('files/'.$file);
}
?>