PHP文件读取问题
$myfile=fopen($filename);while(!feof($myfile)){$myline=fgets($myfile);$recordstr=$rec...
$myfile=fopen($filename);
while(!feof($myfile))
{
$myline=fgets($myfile);
$recordstr=$recordstr.$myline;
}
fclose($myfile);
Warning: fopen() expects at least 2 parameters, 1 given in E:\myPHP\teachos\read.php on line 23
Warning: feof(): supplied argument is not a valid stream resource in E:\myPHP\teachos\read.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in E:\myPHP\teachos\read.php on line 26
怎么解决呢??跪求答案!~~
还有我要是改成用
$myflie=file("$filename");
print_r($myfile);
for($i=0;$i<count($myfile);$i++)
{
$recordstr=$recordstr.$myfile[$i];
//$mysite[i]=explode("|",$myfile[i]);
}
网页空白,跪求答案!~~ 展开
while(!feof($myfile))
{
$myline=fgets($myfile);
$recordstr=$recordstr.$myline;
}
fclose($myfile);
Warning: fopen() expects at least 2 parameters, 1 given in E:\myPHP\teachos\read.php on line 23
Warning: feof(): supplied argument is not a valid stream resource in E:\myPHP\teachos\read.php on line 24
Warning: fgets(): supplied argument is not a valid stream resource in E:\myPHP\teachos\read.php on line 26
怎么解决呢??跪求答案!~~
还有我要是改成用
$myflie=file("$filename");
print_r($myfile);
for($i=0;$i<count($myfile);$i++)
{
$recordstr=$recordstr.$myfile[$i];
//$mysite[i]=explode("|",$myfile[i]);
}
网页空白,跪求答案!~~ 展开
4个回答
展开全部
少了一个参数,fopen需要指定文件名和打开方式(读、写、……)
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
$mode可选:
•"r" (Read only. Starts at the beginning of the file)
“r”(只读格式。始于文件的开头)
•"r+" (Read/Write. Starts at the beginning of the file)
“r+”(可读/可写。始于文件的开头)
•"w" (Write only. Opens and clears the contents of file; or creates a new file if it doesn't exist)
“w”(只写格式。打开或清除文件的内容;或者创建一个不存在的文件)
•"w+" (Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist)
“w+”(可读/可写。打开或清除文件的内容;或创建一个不存在的新文件)
•"a" (Write only. Opens and writes to the end of the file or creates a new file if it doesn't exist)
“a”(只写格式。打开文件,并在文件的末尾处书写内容;或创建一个新的文件)
•"a+" (Read/Write. Preserves file content by writing to the end of the file)
“a+”(可读/可写。通过在文件的末尾书写内容来保存文件的内容)
•"x" (Write only. Creates a new file. Returns FALSE and an error if file already exists)
“x”(只写格式。创建一个新的文件)
•"x+" (Read/Write. Creates a new file. Returns FALSE and an error if file already exists)
“x+”(可读/可写。创建一个新的文件。如果文件已经存在,则返回False或产生一个错误)
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
$mode可选:
•"r" (Read only. Starts at the beginning of the file)
“r”(只读格式。始于文件的开头)
•"r+" (Read/Write. Starts at the beginning of the file)
“r+”(可读/可写。始于文件的开头)
•"w" (Write only. Opens and clears the contents of file; or creates a new file if it doesn't exist)
“w”(只写格式。打开或清除文件的内容;或者创建一个不存在的文件)
•"w+" (Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist)
“w+”(可读/可写。打开或清除文件的内容;或创建一个不存在的新文件)
•"a" (Write only. Opens and writes to the end of the file or creates a new file if it doesn't exist)
“a”(只写格式。打开文件,并在文件的末尾处书写内容;或创建一个新的文件)
•"a+" (Read/Write. Preserves file content by writing to the end of the file)
“a+”(可读/可写。通过在文件的末尾书写内容来保存文件的内容)
•"x" (Write only. Creates a new file. Returns FALSE and an error if file already exists)
“x”(只写格式。创建一个新的文件)
•"x+" (Read/Write. Creates a new file. Returns FALSE and an error if file already exists)
“x+”(可读/可写。创建一个新的文件。如果文件已经存在,则返回False或产生一个错误)
展开全部
$myfile=fopen($filename);
少了一个必须的参数,读取内容的大小。如果是读取整个文件可以:
$myfile=fopen($filename,filesize($filename));
也可以读取指定大小,后面的单位我忘了是kb还是字节
少了一个必须的参数,读取内容的大小。如果是读取整个文件可以:
$myfile=fopen($filename,filesize($filename));
也可以读取指定大小,后面的单位我忘了是kb还是字节
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
少了一个参数,fopen需要指定文件名和打开方式
你改成 $myfile=fopen($filename,'r');
这样应该没问题了。
你改成 $myfile=fopen($filename,'r');
这样应该没问题了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
fopen($filename);要两个参数,第一个是文件名,第二个是读写方式。
一般用r就好了
一般用r就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询