Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中打开.bat文件_Php_Hex_Batch File_Hex Editors - Fatal编程技术网

在php中打开.bat文件

在php中打开.bat文件,php,hex,batch-file,hex-editors,Php,Hex,Batch File,Hex Editors,我想制作一个在线php hexeditor,用户上传一个文件,服务器对其执行指定的hexedit,然后将新文件保存在服务器上。我想我应该编写一个.bat文件,在windows上打开一个十六进制编辑器,执行指定的操作,然后返回新文件。我可以使用php函数system(),或者类似的东西。有谁知道一个好方法来完成这一切吗?您当然可以只使用PHP来实现这一点 您需要做的是: 以二进制形式读取文件 转换为十六进制表示法 以您喜欢的方式显示它 查看函数,这里有一个示例演示如何将文件读取为二进制文件 然

我想制作一个在线php hexeditor,用户上传一个文件,服务器对其执行指定的hexedit,然后将新文件保存在服务器上。我想我应该编写一个.bat文件,在windows上打开一个十六进制编辑器,执行指定的操作,然后返回新文件。我可以使用php函数system(),或者类似的东西。有谁知道一个好方法来完成这一切吗?

您当然可以只使用PHP来实现这一点

您需要做的是:

  • 以二进制形式读取文件
  • 转换为十六进制表示法
  • 以您喜欢的方式显示它
查看函数,这里有一个示例演示如何将文件读取为二进制文件

然后使用函数,该函数将为您提供二进制数据的十六进制表示形式

下面是一个简单的例子:

<?php
$filename = "c:\\files\\somepic.gif";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);

$cols = 8;
$hex = bin2hex($contents);
$hex_split = str_split($hex,4*$cols);

foreach($hex_split as $h)
{
  $tmp = str_split($h, 4);
  foreach($tmp as $t)
    echo $t.' ';
  echo "\r\n";
}
?>

您当然可以只使用PHP来实现这一点

您需要做的是:

  • 以二进制形式读取文件
  • 转换为十六进制表示法
  • 以您喜欢的方式显示它
查看函数,这里有一个示例演示如何将文件读取为二进制文件

然后使用函数,该函数将为您提供二进制数据的十六进制表示形式

下面是一个简单的例子:

<?php
$filename = "c:\\files\\somepic.gif";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);

$cols = 8;
$hex = bin2hex($contents);
$hex_split = str_split($hex,4*$cols);

foreach($hex_split as $h)
{
  $tmp = str_split($h, 4);
  foreach($tmp as $t)
    echo $t.' ';
  echo "\r\n";
}
?>

你计划在一个.bat文件中做什么,而你在PHP中做不到?你计划在一个.bat文件中做什么,而你在PHP中做不到?非常感谢!!在我打开文件后,你能帮我写和编辑它吗?而且,当我试图用一个非常大的文件来做这件事时,我会出错。这可能只是php的一个局限性吗?为了将来的参考,我记得读过一些关于php在处理2gb以上文件时遇到问题的文章。非常感谢!!在我打开文件后,你能帮我写和编辑它吗?而且,当我试图用一个非常大的文件来做这件事时,我会出错。这可能只是php的一个局限性吗?为了将来的参考,我记得读过一些关于php在处理2gb以上的文件时遇到问题的文章。