取消链接PHP数组中的文件(PHPMailer) [英] Unlinking files in PHP array (PHPMailer)
本文介绍了取消链接PHP数组中的文件(PHPMailer)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个简单的问题-你好,顺便说一句,它一直在删除我的问候.
Just a simple question -hello btw, it keeps deleting me my greeting.
这就是我遍历数组并上传文件的方式
This is how I go through an array and upload files
$numFiles = count(array_filter($_FILES['priloha']['name']));
for ($i = 0; $i < $numFiles; ++$i) {
$target_path = './' . basename($_FILES['priloha']['name'][$i]);
if(move_uploaded_file($_FILES['priloha']['tmp_name'][$i], $target_path))
{
echo "Soubor ".basename($_FILES['priloha']['name'][$i])." byl úspěšně nahrán.<br />";
}
$mail->AddAttachment($target_path);
}
现在,发送后,我需要再次遍历数组并删除所有文件,就像处理单个文件(不是数组)一样
Now after sending, I need to go through the array again and delete all the files like I did with a single file (not an array)
if ($mail->AddAttachment($target_path); !="")
{
unlink("$target_path");
}
代码看起来如何?我不太确定,我仍然不知道我可以从第一个"for"循环中删除什么.谢谢您的帮助
How is the code gonna look like? I'm not really sure, I still don't know what can I delete from the first "for" cycle. Thanks for your help
解决了,谢谢Ivo Pereira:)
Solved, thanks Ivo Pereira :)
推荐答案
尝试一下.如果文件已成功发送,则只能将其删除.
Try this. You only delete the file if is it has been successfully sent.
$numFiles = count(array_filter($_FILES['priloha']['name']));
for ($i = 0; $i < $numFiles; ++$i) {
$target_path = './' . basename($_FILES['priloha']['name'][$i]);
if(move_uploaded_file($_FILES['priloha']['tmp_name'][$i], $target_path))
{
echo "Soubor ".basename($_FILES['priloha']['name'][$i])." byl úspěšně nahrán.<br />";
}
if ($mail->AddAttachment($target_path) )
{
unlink("$target_path");
}
}
这篇关于取消链接PHP数组中的文件(PHPMailer)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文