0

I'm a bit noob in php and i'm trying to write a simple page with button inside, these buttons just run php tasks

Obviously, 2 buttons work but the last one not

<!DOCTYPE html>
<html>
<head>
        <title>
                Update Post Mise à Jour
        </title>
</head>
<body style="text-align:center;">
        <h1 style="color:blue;">
                Welcome back
        </h1>
       
        <?php
                if(isset($_POST['button1'])) {
                        $file = 'example.php';
                        $newfile = 'example.txt.bak';
                        echo "La copie est faite";

                        if (!copy($file, $newfile)) {
                        echo "La copie $file du fichier a échoué...\n";
                        }

                }
                if(isset($_POST['button2'])) {

                        $lines1 = file( '/var/www/html/EmailService.php', FILE_IGNORE_NEW_LINES );
                        $lines2 = file( '/var/www/html/EmailServicecopy.php', FILE_IGNORE_NEW_LINES );

                        $result = array_diff( $lines1, $lines2 );
                        print_r( $result );
                }
                if(isset($_POST['button3'])) {

                        $filename = "/var/www/html/EmailService.php";
                        $fichier = fopen($filename, 'c+b');
                        $texte = fread($fichier, 5454);
                        $filename2 = "/var/www/html/motif.txt";
                        $fichier2 = fopen($filename2, 'r');
                        $texte .= fread($fichier2, filesize($filename2));
                        $texte .= fread($fichier, filesize($filename));
                        fseek($fichier, 0);
                        fwrite($fichier, $texte);
                        fclose($fichier);
                        fclose($fichier2);
                        
                echo "Update effectué";
                }
        ?>
        <form method="post">
                <input type="submit" name="button1" value="Copie de EmailService"/>

                <input type="submit" name="button2" value="Check des fichiers"/>

                <input type="submit" name="button3" value="Update du script"/>
        </form>
</body>
</html>

The first and second if(isset($_POST['button1'])) { work but the third not I got the answer Update effectué but my file is not modified

When i put

<?php
                        $filename = "/var/www/html/EmailService.php";
                        $fichier = fopen($filename, 'c+b');
                        $texte = fread($fichier, 5454);
                        $filename2 = "/var/www/html/motif.txt";
                        $fichier2 = fopen($filename2, 'r');
                        $texte .= fread($fichier2, filesize($filename2));
                        $texte .= fread($fichier, filesize($filename));
                        fseek($fichier, 0);
                        fwrite($fichier, $texte);
                        fclose($fichier);
                        fclose($fichier2);
?>

in a file and i run php file.php, then it works

I'm a bit lost What am i doing wrong ?

  • 1
    Start by getting [PHP to display errors](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) and see if there are any. – El_Vanja Mar 21 '21 at 09:32

1 Answers1

0

Noob problem solved :))

It was permission problem, new created scripts don't have correct permissions