how to create a php script that makes a screenshot and modify the name each time it takes the capture

5

good, my question is the following as I can do to make a script in php that at the time of taking the screenshot I modified the name and I did not change the image already saved .. my code is as follows:

<?php

function reporte($i){
    require ('config.php');
    $i++;
    $Nombre = "Reporte".$i;
    $guardado = "../img/".$Nombre.".jpeg";
    $img = imagegrabscreen();
    $destino_1 = imagejpeg($img,$guardado);


            $conexion = mysqli_connect($db_host,$db_user,$db_pass);
            if (mysqli_connect_errno()) {
                echo "Fallo al conectar con la Base de Datos.";

                exit();

            }

            mysqli_select_db($conexion, $db_bd) or die ("No se encontro la Base de Datos");

            mysqli_set_charset($conexion, "utf8");
    $guardar= "INSERT INTO img (ID, Nombre, Lugar) VALUES (0, '$Nombre', '$guardado') ";

        $resultado=mysqli_query($conexion,$guardar);

        mysqli_close($conexion);
    sleep(30)
    return $Nombre(); 
}
while (true) {
    $i(2);
}
?>

Well the truth is I'm not very good at php but what little I know and what I researched is what I do, and I've already searched several pages but I do not get anything. What do I want to do with my script so I take a screen capture every 15min and I save the photo in the database, in this case I just saved the path so as not to occupy much space in the database, but I get an error time to use the sleep () and when I save the photo it replaces the previous one that I had already taken. in advance thank you very much

    
asked by Hayate GS 24.08.2018 в 21:23
source

2 answers

1

You have several logic errors. First, the variable $i should be a global variable. Then in the while you would call your function with that global variable. Finally, you need to differentiate between the global variable and the function parameter. You can change the name to $j and always subtract the global variable within the function. Something like this:

<?php
$i = 2;
function reporte($j){
    require ('config.php');
    $i++;
    $Nombre = "Reporte".$j;
    $guardado = "../img/".$Nombre.".jpeg";
    $img = imagegrabscreen();
    $destino_1 = imagejpeg($img,$guardado);    

            $conexion = mysqli_connect($db_host,$db_user,$db_pass);
            if (mysqli_connect_errno()) {
                echo "Fallo al conectar con la Base de Datos.";

                exit();

            }

            mysqli_select_db($conexion, $db_bd) or die ("No se encontro la Base de Datos");

            mysqli_set_charset($conexion, "utf8");
    $guardar= "INSERT INTO img (ID, Nombre, Lugar) VALUES (0, '$Nombre', '$guardado') ";

        $resultado=mysqli_query($conexion,$guardar);

        mysqli_close($conexion);
    sleep(30);
    return $Nombre; 
}
while (true) {
    reporte($i);
}
?>

Another thing, this script would never finish running. Maybe it's better to do a cron instead of while .

    
answered by 24.08.2018 / 22:39
source
0

Thank you very much for answering and I answered my question: D was also looking for cron and while that ends thinking of something: D! to whom I give my code that was what I did: D !!!

<?php
$i=0;
while ($i<=3) {
    require ('config.php');
    $i++;
    $Nombre = "Reporte".$i;
    $guardado = "../img/".$Nombre.".jpeg";
    $img = imagegrabscreen();
    $destino_1 = imagejpeg($img,$guardado);    

            $conexion = mysqli_connect($db_host,$db_user,$db_pass);
            if (mysqli_connect_errno()) {
                echo "Fallo al conectar con la Base de Datos.";

                exit();

            }

            mysqli_select_db($conexion, $db_bd) or die ("No se encontro la Base de Datos");

            mysqli_set_charset($conexion, "utf8");
    $guardar= "INSERT INTO img (ID, Nombre, Lugar) VALUES (0, '$Nombre', '$guardado') ";

        $resultado=mysqli_query($conexion,$guardar);

        mysqli_close($conexion);
    sleep(5);
}
?>
    
answered by 24.08.2018 в 23:03