开发者

how to concatenate files according check box selection using system call in php

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


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 ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜