我有以下应该存在的警告,但是有没有办法在不实际禁用警告的情况下阻止它们写到页面?
警告:
警告:file_get_contents(E:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(F:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(G:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(H:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(I:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(J:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(K:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(L:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(M:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(N:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(O:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
警告:file_get_contents(P:/connected.txt):无法打开流:第19行的C:\ xampp \ htdocs \ ppa \ test.php中没有此类文件或目录
PHP功能:
//Check if the connection file is present on each drive function scanDrives() { //Possible drives $letters = "DEFGHIJKLMNOP"; $letters = str_split($letters); $code = md5("FMbHSBTMTXhu3TWp"); //Check for a certain file on each device foreach($letters as $x) { $file = file_get_contents($x.":/connected.txt"); //This is what causes the error as the file can't be found. if ($file != false) { $file_code = split(":", $file); //Check if the file has the correct pass code if($file_code[0] == $code) { //Successful, return pass value and device letter and set name echo (1).",".$x.",".$file_code[1]; } } } }
谢谢。
不要只是使用盲目打开文件file_get_contents
。检查它是否首先存在。
if(file_exists($x.":/connected.txt")){ $file = file_get_contents($x.":/connected.txt"); // ... }