0
I am using a file in the main directory of the site, with the following code:
<?php
$diretorioFuncoes = $_SERVER['DOCUMENT_ROOT']."/buscar"; // Dir dos arquivos
$arrayExcecoes = array(); // * Coloque aqui os arquivos que você quer que não sejam incluidos
if ($handle = opendir($diretorioFuncoes))
{
while (false !== ($file = readdir($handle)))
{
if(strpos($file,".php")) // * Só inclui arquivos PHP
{
if(!in_array($file,$arrayExcecoes))
{
include($diretorioFuncoes."/".$filesize);
}
}
}
closedir($handle);
}
?>
This above code makes the "include" of all files with extensions .php
within the "search" directory. And it’s working perfectly.
Within the "search" directory, I have several files with a code that executes an sql query within the database. So far so good. I would like that after the command runs, the file deletes itself, and I am trying this way:
<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (new DateTime() > new DateTime("2015-04-17")) {
# current time is greater than 2010-05-15 (Ano - Mês - Dia)
$sql = "UPDATE `url` SET `type` = 'splash' WHERE `url`.`custom` = '$custom'; ";
if ($conn->query($sql) === TRUE) {
unlink ("$custom.php");
echo ("$custom")," atualizado com sucesso<br><br>";
} else {
echo "Error updating record: " . $conn->error;
}
}
else {
echo ("$custom")," - ainda não está na hora.<br>";
}
$conn->close();
?>
In order for the file to be deleted automatically, I am adding this line:
unlink ("$custom.php");
But when this file is run through include, the unlink command returns me this error:
Warning: unlink(meiamaratonasantoandre2016.php) [Function.unlink]: No such file or directory in /public_html/buscar/meiamaratonasantoandre2016.php on line 21
An important note, is that if I open the file directly by the browser, and not by include, the unlink command works perfectly.
Does anyone know what I might be doing wrong?
Hello Daniel, With the above tip worked too, but I ended up noticing the problem in the original code. It turns out I was running the file through include in a file from another directory, so the mentioned error.
– Wesley
Therefore the recommendation in the use of absolute path. Because regardless of the directory where it is executed, the path will always be found.
– Daniel Omine