Error deleting php file

Asked

Viewed 23 times

1

I am trying to delete a txt file in php and I am experiencing an error

 Warning: unlink() expects parameter 1 to be a valid path, resource given in C:\xampp\htdocs\CoreContactos(4)\download.php on line 6

My code is here

<?php 
    include("conexao.php");
    $arquivo=fopen("emails.txt", 'w');
    if ($arquivo == false) die('Não foi possível criar o arquivo.');
    sleep(10);
    if(!unlink($arquivo)){
        echo"Erro";
    }
    else
    {
        echo"apagado";
    }

 ?>

1 answer

2


Try this:

<?php
include("conexao.php");
$arquivo=fopen("emails.txt",'w');
if ($arquivo == false) die('Não foi possível criar o arquivo.');
fclose($arquivo);
unlink('emails.txt');
while ($texto = sqlsrv_fetch_array($query)){
file_put_contents($txt,$texto,FILE_APPEND);
file_put_contents($txt,"\n",FILE_APPEND);
}
 ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.