<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?
$file = fopen("drug.txt", "r") or die("Can't open file");
echo $file;
?>
</BODY>
</HTML>
我是 php 的新手,并尝试打开此文件,我收到"资源 ID #1"作为错误
> 这不是错误。 $file
是一种资源。您必须使用 fread
从该文件中实际获取一些数据,或者使用 file_get_contents
将整个文件作为字符串读取。
加上马克的评论,以下是可以工作的代码:
<?php
$file = "/usr/local/something.txt";
$handle = fopen($file, "r");
$contents = fread($handle, filesize($file));
fclose($handle);
echo $contents;
?>