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

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

WBOY
Release: 2016-06-23 13:41:16
Original
903 people have browsed it

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

我想合并分割的文件,可是一直提示写入不能写入到文件,把文件名改为txt格式的就可以成功


回复讨论(解决方案)

中文问题吧

$str="宋1.txt";$str=iconv("utf-8", "GBK", $str);//注释掉就会失败$fp = fopen($str, "a");if(fwrite($fp,"losasds")!==false) echo "ok";else echo "fail";fclose($fp);
Copy after login
Copy after login

二进制文件要用二进制方式打开,即模式中要有 b

中文问题吧

$str="宋1.txt";$str=iconv("utf-8", "GBK", $str);//注释掉就会失败$fp = fopen($str, "a");if(fwrite($fp,"losasds")!==false) echo "ok";else echo "fail";fclose($fp);
Copy after login
Copy after login


不是中文的问题,而是后缀.part的问题,不知为什么,反正去掉他就好了
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template