I have this query to see if the file exists inside a folder called _sellos
<?php
$nombre_fichero = 'C:\xampp\htdocs\_sellos92-2018-E01-sellos.pdf';
if (file_exists($nombre_fichero)) {
this name 7992-2018-E01-sellos.pdf is obtained from the result of 3 queries, this way:
7992 = <?php echo substr($contrato['numero_contrato'],0,4) ;?>
2018 = <?php echo $contrato['year']; ?>
E01 = <?php echo substr($contrato['numero_contrato'],-3) ; ?>-sellos.pdf
leaving something like this to generate the name to compare:
<?php $nombre_fichero = 'C:\xampp\htdocs\_sellos\<?php echo substr($contrato['numero_contrato'],0,4) ;?>-<?php echo $contrato['year']; ?>-<?php echo substr($contrato['numero_contrato'],-3) ; ?>-sellos.pdf';
clearly this does not work because I include the? php and?, I have no idea how to do it within the variable without including the? php and?
When testing the answer with the following code the query stops working
$var1 = substr($contrato['numero_contrato'],0,4);
$var2 = $contrato['year'];
$var3 = substr($contrato['numero_contrato'],-3);
$nombre_fichero = "C:\xampp\htdocs\_sellos\$var1-$var2-$var3-sellos.pdf";
if (file_exists($nombre_fichero)) {
echo "El fichero $nombre_fichero existe";
} else {
echo "El fichero $nombre_fichero no existe";
}