更新时间:2023-12-04 20:05:28
您的代码中有一些问题:
You have a few problems in your code:
$uploadedfile
从未声明,但用于查找文件路径.我认为这与$getdeleted
相同.deleteGreetings
建模时会使用整个数组.您应该从循环中删除此函数调用,否则将为数组中的每个元素调用每个函数.您只想调用一次.$uploadedfile
is never declared but it is used to find the file path. I assume this is the same as $getdeleted
.deleteGreetings
takes the entire array. Your should remove this function call from your loop else it will be called each for every element in the array. You only want to call this once.我会做这样的事情:
$arrayIDs = JRequest::getVar ( 'cid', null, 'default', 'array' );
if ($arrayIDs === null) { //Make sure the cid parameter was in the request
JError::raiseError ( 500, 'cid parameter missing from the request' );
}
$model = & $this->getModel ( 'greetings' );
jimport ( 'joomla.filesystem.file' );
if (is_array ( $arrayIDs ) && count ( $arrayIDs ) > 0) {
$del = $model->deleteGreetings ( $arrayIDs );
// check this outside the loop, if it is inside you are checking it for
// each element in the array. Here we check once and then go forward.
if ($del) {
foreach ( $arrayIDs as $k => $id ) {
$uploadedfile = $model->getUploadpic ( $id );
$deletefile = JPATH_COMPONENT . DS . "uploads" . DS . $uploadedfile;
JFile::delete($deletefile);
//unlink ( $deletefile );
}
}
}