如何在 php 中使用系统调用根据复选框选择连接文件

发布于 2024-09-02 06:50:11 字数 106 浏览 3 评论 0原文

我在 php 中有一些文件,我需要在选择复选框的基础上进行连接。如果选择了一个复选框,则根据要求进行连接等等。我必须使用系统调用来完成此操作,并且我正在 php 和 ssh 中工作(安全外壳客户端)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕色琉璃 2024-09-09 06:50:11

假设您将文件放入数组中,使用 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,具体取决于您的系统配置。
我很想知道哪里需要通过系统调用来执行此操作,这些文件大吗?

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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文