Selamlar herkese.

$dbirlestir döngü değerine gelen satırı kopyalamak istiyorum. Her satırı ayrı ayrı değil, döngü sonundaki son değeri hep kopyalıyor.

            <?php
            foreach ($dosyalar as $dosya) {
                if ($dosya != "." && $dosya != "..") {
                    $dosyaYolu = $klasor . $dosya;
                    $dosyaBilgisi = pathinfo($dosyaYolu);
                    $dbirlestir = $dosyaBilgisi['filename'].".".$dosyaBilgisi['extension'];
                    $MB = filesize($dosyaYolu)/1024;

                // Dosya türüne göre işlemler
                    if (in_array($dosyaBilgisi['extension'], ['jpg', 'jpeg', 'bmp', 'png', 'pdf', 'docx', 'xlsx', 'svg', 'webp', 'mp4'])) {
                    // Dosya bilgilerini göster
                        echo '<tr>';
                        echo '<td><a href="?link=sil&dosya='.$dbirlestir.'&dil='.$dil.'">'.constant('DELETE').'</a></td>';
                        echo '<td><a href="../../../upload/'.$dbirlestir.'" download>'.constant('DOWNLOAD').'</a></td>';
                        echo '<td>'.$dbirlestir.'<br>
                        <a style="cursor:pointer" onclick="coklu()">'.constant('COPY').'</a></td>';
                        echo "<td>".number_format($MB,0)." MB</td>";
                        echo "<td>";

                        if (in_array($dosyaBilgisi['extension'], ['jpg', 'jpeg', 'bmp', 'png', 'webp'])) {
                            echo "<a target='_blank' href='../../../upload/".$dbirlestir."'><img height='100' src='".$dosyaYolu."' alt='".$dosyaBilgisi['filename']."'></a>";
                        } 
                        if (in_array($dosyaBilgisi['extension'], ['mp4'])) {
                            echo "<a target='_blank' href='../../../upload/".$dbirlestir."'><video height='100' controls src='".$dosyaYolu."'></video></a>";
                        }
                        echo "</td></tr>";
                    }
                }
            }
            ?>
        </tbody>
    </table>
    <script>
        function copyText (text) {
          const element = document.createElement('textarea');
          element.value = text;
          document.body.appendChild(element);
          element.focus();
          element.setSelectionRange(0, element.value.length);
          document.execCommand('copy');
          document.body.removeChild(element);
      }

      function coklu() {
        alert('Dosya Adı Kopyalandı: <?php echo $dbirlestir; ?>');
        copyText("<?php echo $dbirlestir; ?>");
    }
</script>