tags:

views:

98

answers:

1

I have some files in php ,i need to concatenate on basis of selection of checkboxes.if one checkbox is selected concatenate according to requirement and so on.this i have to do using system call ,and i'm working in php and ssh (secure shell client)

A: 

Assuming you get files into an array, with HTML like

<?php
$files = array('file1.txt', 'file2.txt', 'file3.txt'); 
?>
<form action="action.php" method="post">
   <?php foreach ($files as $k => $files) { ?>
      <input type="checkbox" name="files[<?php echo $k;?>]" value="<?=$k;?>" />
   <?php } ?>
   <input type="submit" name="submit" value="ok" />
</form>

You can access checked checkboxed with php

<?php
    //I've made assumption outfile is in same path as source files
    $path = '/var/www/whatever/to/files/';
    $dest_file = $path . 'out.txt';
    //create empty file if not exists
    passshtru("touch $dest_file;");
    foreach ($_POST['files'] as $key) {
      $source_file = $path . $files[$key];
      //co contactenation using shell redirect
      passthru("cat $source_file >> $dest_file;");
    }

    //do whatever you want with generated file in /var/www/whatever/to/files/out.txt

You could need to put real path to binaries touch and cat, depending on your system config. I'm curious to know where is the need to do this with system calls, is theses files big ?

Benoit