Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!