【问题标题】:how to concatenate files according check box selection using system call in php如何使用php中的系统调用根据复选框选择连接文件
【发布时间】:2010-05-17 12:00:06
【问题描述】:

我在 php 中有一些文件,我需要根据复选框的选择进行连接。如果选择了一个复选框,则根据要求连接等等。我必须使用系统调用来做,我正在使用 php和 ssh(安全 shell 客户端)

【问题讨论】:

  • 如果你在这里粘贴你的试用代码,我会明白你需要什么,但我更喜欢你也提供一些你已经完成的工作来获得输出......
  • 你需要连接什么? php文件?复选框选择了什么?什么复选框?什么是“按要求”?为什么要系统调用?您需要更加准确和详细,我们才能回答您的问题。

标签: php system-calls


【解决方案1】:

假设您将文件放入数组中,使用 HTML 之类的

<?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>

您可以使用 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

您可能需要输入二进制文件touchcat 的真实路径,具体取决于您的系统配置。 我很想知道系统调用在哪里需要这样做,这些文件很大吗?

【讨论】:

    猜你喜欢
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 2016-05-24
    • 2021-11-07
    • 2021-10-29
    • 1970-01-01
    相关资源
    最近更新 更多