I'm 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 code above does "include" all files with .php
extensions inside the "search" directory. And it's working perfectly.
Inside the "search" directory, I have several files with a code that executes a sql query inside the database. So far so good. I would like that after the command is executed, the file would auto-exclude itself, and I am trying to do this:
<?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();
?>
For the file to be deleted automatically, I am adding this line:
unlink ("$custom.php");
But when this file is executed through include, the unlink command returns this error:
Warning: unlink (meiamaratonasantoandre2016.php) [function.unlink]: No such file or directory in /public_html/search/meiamaratonasantoandre2016.php on line 21
One important note is that if I open the file directly through the browser, not through the include, the unlink command works perfectly.
Does anyone know what I might be doing wrong?