对于在文件管理中复制文件,我使用可以单击的复选框。每个复选框都有自己的值;文件!比如:
uploads/image1.jpg
或
uploads/image2.jpg
所有值都绑定到1个变量,
$checkboxfiles
(这是一个文件数组)。
为了将选中的文件复制到另一个文件夹,我检查在该文件夹中是否已经存在同名的文件。如果是,我将显示一个弹出窗口,其中包含一个表单,以确认是否覆盖。
php代码:
// Multiple copy and move (checkboxes)
if( isset($_POST["checkboxes_value"]) && isset($_POST["cbdestination"]) ) {
$checkboxfiles = explode("," , $_POST["checkboxes_value"]); // contains multiple values of files
foreach($checkboxfiles as $checkboxfile) {
$src_file = $checkboxfile;
$fileName = basename($src_file);
$new_dest = $_POST['cbdestination'];
/* New path for this file */
$dest_file = $MainFolderName.'/'. $new_dest . '/' . $fileName;
/* check for overwriting */
$allow = $_POST['overwrite'];
if($allow == '') { // if not empty, the request comes from the popup and is confirmed
if(file_exists($dest_file)) {
include('alerts/file_copy_exists.php'); // includes a form to confirm overwriting
exit; // i must use this and wait for confirmation
}
}
$copy = copy( $src_file, $dest_file );
// and so on...
} // end foreach
问题:假设我检查了3个文件,并想将它们复制到另一个文件夹。在文件夹中已有2个同名。在这种情况下,我必须使用
exit;
在覆盖循环中等待确认。但是当我使用出口时,前哨不再工作了。只显示最后一个文件的弹出窗口。
当不使用
出口;
,出现2个弹出窗口确认。但在这种情况下,文件已经被覆盖。所以这些弹出窗口没用!
我该如何处理这种情况?