duanduan1993
2011-10-22 10:59
浏览 43
已采纳

PHP exec拆分命令在linux服务器上

I have a linux server running ubuntu 10.10 maverick with apache and php installed, in the /var/www directory I have a download directory. I have used OSFile manager and modified to include a function to split files here is the code:

function spl($fname){
 global $folder;
 if (!$fname == ""){
    maintop("Split");
    $dirfile = $folder.$fname;

    \\escape directory path
    $dirfile = str_replace(" ","\ ",$dirfile);
    $dirfile = str_replace("(","\(",$dirfile);
    $dirfile = str_replace(")","\)",$dirfile);
    $command = "split -d -b1024m ".$dirfile." ".$fname."_";
    echo "Command: ".$command;
    echo"<br />";


    $returnval =0;
    unset($output2);
    $output = exec($command,$output2,$returnval);

    //echo results
    echo($output);
    echo"<br />";
    print_r($output2);
    echo"<br />";
    echo($returnval);
    echo"<br />";
    mainbottom();
 }
  else
    home();
}

The command does not execute. The file and directory is correct but it returns exit code 1, and Array() as the output values, I have created a group that includes a few users, I have made this group the owner of downloads/ and given it read write and execute permissions, this group includes www-data.

Any Help will be apreciated

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongwuli5105 2011-10-22 12:00
    已采纳

    IF you don't get any error messages from exec and the error.log stays empty, then use this wrapper for executation:

     exec("sh -c \" $cmd 2>&1 \"");
    

    The 2>&1 redirects the stderr channel to stdout, so that it shows up in the result array.
    In the shell, what does " 2>&1 " mean?

    Another option would be proc_open where you can read each channel separately, but is more work to set up.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duangu4980 2011-10-22 11:29

    try this file split class

    Split and merge files

    or this using exec Split big files using PHP using exec

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题