Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中存在出口时在foreach循环中传递值_Php_Checkbox_Foreach_Exit - Fatal编程技术网

如何在php中存在出口时在foreach循环中传递值

如何在php中存在出口时在foreach循环中传递值,php,checkbox,foreach,exit,Php,Checkbox,Foreach,Exit,关于这种情况: 对于在文件管理中复制文件,我使用可以单击的复选框。每个复选框都有自己的值;档案!例如:uploads/image1.jpg或uploads/image2.jpg 所有值都绑定到一个变量,$checkboxfiles(因此它是一个文件数组)。 为了将选中的文件复制到另一个文件夹,我会检查该文件夹中是否已存在同名文件。如果是,我将显示一个带有表单的弹出窗口,以确认是否覆盖 php代码: // Multiple copy and move (checkboxes) if( isset(

关于这种情况:

对于在文件管理中复制文件,我使用可以单击的复选框。每个复选框都有自己的值;档案!例如:
uploads/image1.jpg
uploads/image2.jpg

所有值都绑定到一个变量,
$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个文件,并想将它们复制到另一个文件夹。该文件夹中已存在其中两个同名文件夹。在这种情况下,我必须使用
退出并等待确认。但当我使用出口时,foreach不再工作。仅显示最后一个文件的弹出窗口

不使用
退出时,出现两个弹出窗口以确认。但在这种情况下,文件已经被覆盖。所以这些弹出窗口是无用的


我如何处理这种情况

如果文件不存在,请使用else。或者,您实际上应该使用jQuery,因为您需要后端和前端交互,我同意!覆盖中的else给出了一个转义,我不需要
退出不再!简单但非常有用的解决方案。如果文件不存在,请使用else。或者,您实际上应该使用jQuery,因为您需要后端和前端交互,我同意!覆盖中的else给出了一个转义,我不需要
退出不再!简单但非常有用的解决方案。thnx