不能让它工作!啊。现在,如果我从 /uploads 中删除 test.rar,我想从中删除它,$row['attachments']
但它不会!有一段时间一直在挠头...
我在这里做错了什么?
$row['attachments'] = "angeleyes.jpg|test.rar"; // in reality i get this from the database
$attachments = explode('|', $row['attachments']);
$dir = "../uploads/";
if ($row['attachments']) {
foreach($attachments as $file) {
if(is_file($dir.$file))
echo '<a href="#">'.$file.'</a> ('.filesize_formatted($dir.$file).') <br>';
// If file wasnt found, clean up
else {
// Remove it
$list_of_attachments = $row['attachments'] ? explode("|", $row['attachments']) : array();
if(!in_array($file, $list_of_attachments)) $list_of_attachments[] = $file;
$newstring = implode("|", $list_of_attachments);
// lets see if it works
var_dump($newstring);
// update db
}
}
}