将以下php代码改成JavaScript代码define('__QQWRY__' , dirname(__FILE__)."/dd.dat");
$fp= fopen(__QQWRY__, "rb");
if ($fp == NULL) {
$szLocal= "OpenFileError";
return 1;
}
$contents.=fread ( $fp , 20 ) ;//读取文件头
$value =fread ( $fp , 4 ) ;//读取号码长度
$format = 'C1num/a7code/imoney';
$length = 1 + 7 + 4;
$i=0;
while (!feof($fp)) {
$data =fread ( $fp , $length ) ;
$bianbian = @unpack("$format", $data);
if(!empty( $bianbian)){
$getarray[$i]['n'] = substr($bianbian['code'],0,$bianbian['num']);
$getarray[$i]['m'] = $bianbian['money'];
$i++;
}
} 分不够可以再加
$fp= fopen(__QQWRY__, "rb");
if ($fp == NULL) {
$szLocal= "OpenFileError";
return 1;
}
$contents.=fread ( $fp , 20 ) ;//读取文件头
$value =fread ( $fp , 4 ) ;//读取号码长度
$format = 'C1num/a7code/imoney';
$length = 1 + 7 + 4;
$i=0;
while (!feof($fp)) {
$data =fread ( $fp , $length ) ;
$bianbian = @unpack("$format", $data);
if(!empty( $bianbian)){
$getarray[$i]['n'] = substr($bianbian['code'],0,$bianbian['num']);
$getarray[$i]['m'] = $bianbian['money'];
$i++;
}
} 分不够可以再加
漏了一个地址问题,这个地址是用户在电脑上面预览的地址。这样就可以解决fopen问题了吧。
再js中可以直接
<FORM name=form1 METHOD=POST ACTION="">
<INPUT TYPE="file" NAME="browser" >
<INPUT TYPE="button" VALUE="解析" ONCLICK="ShowFileInfo(form1.browser.value)">
</FORM>
<script>
function ShowFileInfo(url){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpentextFile(url);//打开
}
</script>