php如何循环传递数据,在PHP中有一个出口时如何在PURACH循环中传递一个值

对于在文件管理中复制文件,我使用可以单击的复选框。每个复选框都有自己的值;文件!比如:

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个弹出窗口确认。但在这种情况下,文件已经被覆盖。所以这些弹出窗口没用!

我该如何处理这种情况?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值