在文件数组php上实现重命名功能

I'll explain this as best I can, as it stands I'm having trouble implementing a function to rename a file, ive currently got a list files function which is called on my web page making it look like so:

enter image description here

I want to create another rename button which changes the file name to the users in-putted value, currently the function is as follows:

<?php
function renameFile($dir, $fileToRename, $newname){
if (is_dir($dir)) {
    if ($dirHandle = opendir($dir)) {
       $files = array_diff(scandir($dir), array('.', '..', '.htaccess'));
       if($files){
           foreach($files as $file){
               if($file === $fileToRename) {
                  rename($dir."\\".$fileToRename, $dir."\\".$newname );
                  $output = 'Successfully renamed file: '.$fileToRename;
               }
           }
       }
    }
}
return $output;
    }
'<form>
<input type="text" id="newname"/>
<input type="hidden" value="'.$file.'" name="fileToRename"/>
<input type="button" value="rename" onclick="rename($dir, $fileToRename, this.newname)"/>
</form>'



?>

I'll also add the code for listing the files as it may be relevant:

function listFiles($dir)
{
    function deleteFile($dir, $fileToDelete){
if (is_dir($dir)) {
    if ($dirHandle = opendir($dir)) {
       $files = array_diff(scandir($dir), array('.', '..', '.htaccess'));
       if($files){
           foreach($files as $file){
               if($file === $fileToDelete) {
                  unlink($dir."\\".$fileToDelete);
                  $output = 'Successfully deleted file: '.$fileToDelete;
               }
           }
       }
    }
}
return $output;
    }
    if(isset($_POST)){
echo deleteFile($_SESSION['UserFolder'], $_POST['fileToDelete']);
}

    {
$output = '';  $outRows = '';  $files = array();
if (is_dir($dir)) {
    if ($dirHandle = opendir($dir)) {
    $files = array_diff(scandir($dir), array('.', '..', '.htaccess'));
    $totalSize = (int) 0;
    foreach($files as $file) {
        $fileTime = @date("d-M-Y", filectime($dir . '/' . $file)) . ' ' . @date("h:i",          filemtime($dir . '/' . $file));
        $totalSize += filesize($dir . '/' . $file);
        $fileSize = @byte_convert(filesize($dir . '/' . $file));
        $cellLink = '<td class="list_files_table_file_link"><a href="'. $dir ."/".          $file     . '">' . $file . '</a></td>';
        $cellTime = '<td>' . $fileTime . '</td>';
        $cellOptions = '<td>'. '<form action="MyFiles.php" method="POST"><input type="hidden" value="'.$file.'" name="fileToDelete"/><input type="submit" value="Delete" name="deleteButton"/></form>' .'<td>';
        $cellSize = '<td>' . $fileSize . '</td>';
       //$deleteCell = '<td><form action="Delete.php" method="POST"><input                  type="hidden" value="'.$file.'" name="fileToDelete"/><input type="submit"               value="click" name="deleteButton"/></form></td>';
    $outRows .= '<tr>' . "
  " . $cellLink . "
  " . $cellTime . "
  " . $cellSize   . "
" . $cellOptions . '</tr>' . "
";
  }
  closedir($dirHandle);
}

The form will be called in $cellOptions as to have the search button along side the delete button to apply to the correct files. I've tried implementing it but keep being thrown errors like :

syntax error, unexpected (T_CONSTANT_ENCAPSED_STRING)

among a couple of others, am I overlooking something ? Or just doing this wrong in general I know this is long but I really appreciate you taking your time to read it

I think you need to change this line

rename($dir."\\".$fileToRename, $dir."\\".$newname );

to

rename('.$dir."\\".$fileToRename.', '.$dir."\\".$newname.' );

You know i think in this:

if(file_put_contents(file_get_contents($customName),$newName)){
deleteFunction($custonName);
}

I have not tried it but I think it would work PD: my english is not good