Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
How to copy a file then rename it based on input field via buttonclick?

Good day experts!

I want to copy a file and rename it based on input value via button click. MY code is not working. There is no file being copied nor being renamed. Here's my code:

<?php
error_reporting(0);

if($_POST['action'] == 'call_this') {
  echo Success!;
};

$file = 'data.php';
$newfile = '$_GET['subject'].php';
echo copy($file, $newfile);
  
?>

<form action="<?php echo $newfile ?>" method="get">
<input type="text" name="subject" required>
<button type="submit"><a href="" onclick="change()">Change</a></button>
</form>

<script>
function change() {
      $.ajax({
           type: "POST",
           url: 'data.php',
           data:{action:'call_this'},
           success:function(html) {
             alert(html);
           }

      });
 }
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

i think this is what you looking for:

<html>
<body>
<form method="post" action="copy.php">
<input type="text" placeholder="new name" name="newFileName"/>
<input type="submit" value="Change"/>
</form>
</body>
</html>

copy.php :

<?php
$file = 'sample.txt';
$newfile = $_POST["newFileName"].'.txt';

if (!copy($file, $newfile)) {
    echo "failed to copy";
}else {
    echo "copy with new name";
}
?>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda