简体   繁体   中英

How to delete file from folder on server which is sent as an attachment in a mail using PHP

I want to delete pdf from folder which is sent as an attachment in a mail on a server. I am trying this code :

if($mail->Send()) 
{
 unlink($file);
}

Its working on local but not on server. Thanx in advance.

If it is working on local, it means your file path is correct on your local project. I am sure that path of the same file is different and not correct that's same php built-in function unlink() does not working on server. You just need to provide correct path of the file, also you can use file_exists() which will check that file is available or not.

$file = '../your-directory/your_file.pdf';
if (file_exists($file)) {
    unlink($file);
}

Also check the file permission because php function will be unable to delete any file if file has read only permission.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM