Home >Backend Development >PHP Tutorial >php的文件读取跟写入似乎对未知格式的文件不管用

php的文件读取跟写入似乎对未知格式的文件不管用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:14:041005browse

php的文件读取和写入似乎对未知格式的文件不管用

<br /><?php<br />$file="宋1.mp3.part1";<br />$file1="宋2.mp3.part1";<br />$file2="宋3.mp3.part1";<br />$fp = fopen($file, "a");<br />$fp1 = fopen($file1, "r");<br />$fp2 = fopen($file2, "r");<br />// if(!$fp1) echo "aa";<br />// return;<br />//fseek(fp, 0, SEEK_END);<br />$index=0;<br /> while(!feof($fp1)){//测试文件指针是否到了文件结束的位置 <br />        $content=fread($fp1,10); <br />        if(fwrite($fp,$content)==false)<br />		echo "不能写入到文件 $filename"; <br />		$index++;<br />		echo $index;<br />    } <br />	$index=0;<br />	while(!feof($fp2)){//测试文件指针是否到了文件结束的位置 <br />        $content=fread($fp2,10); <br />        fwrite($fp,$content); <br />			$index++;<br />		echo $index;<br />    } <br />    fclose($fp);  <br />    fclose($fp1); <br />    fclose($fp2); <br />	rename ($file, "a.mp3"); <br />	echo "ok";<br />?><br />

我想合并分割的文件,可是一直提示写入不能写入到文件,把文件名改为txt格式的就可以成功
------解决思路----------------------
中文问题吧
<br />$str="宋1.txt";<br />$str=iconv("utf-8", "GBK", $str);//注释掉就会失败<br />$fp = fopen($str, "a");<br />if(fwrite($fp,"losasds")!==false) echo "ok";<br />else echo "fail";<br />fclose($fp);<br />

------解决思路----------------------
二进制文件要用二进制方式打开,即模式中要有 b

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn