使用php创建文件的问题 [英] Problem with creating a file using php

查看:69
本文介绍了使用php创建文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个php脚本。

我想从我的服务器打开一个文件(如果它不存在,然后创建一个新文件)并在textarea中显示内容。



我的代码是,

 <   textarea     name   =  text     =  25    cols   =  100 >  
<? php

$ fn = $ SERVER [' DOCUMENT ROOT'] '/ nink / hai.txt';

$ fh = fopen($ fn,< /跨度> r);

< span class =code-summarycomment> fclose($ fh);

echo file_get_contents( $ fn);

>
< / textarea >





当我重新加载页面时,textarea充满了,

 <   br     /  >  
< b > 警告< / b > :fopen(/nink/hai.txt)[< a href =' function.fopen' > function.fopen < / a > ]:无法打开流:< b > /home/www/imwazir.net/nink /index.php< / b > on line < b > 23 < / b > < br / >
< br / >
< b > 警告< / b > :fclose()要求参数1为资源,在< <中给出布尔值span class =code-leadattribute> b > /home/www/imwazir.net/nink/index .php < / b > 在线< b > 24 < / b > < br / >
< br / >
< b > ; 警告< / b > :file_get_contents(/nink/hai.txt)[< a href =' function .file-get-contents' > function.file-get-contents < / a > ]:无法打开流:< b > /home/www/imwazir.net /nink/index.php< / b > 在线< b > 25 < / b > < br / >





我将nink文件夹的权限更改为777,但我仍然收到错误。

我做错了什么?我该怎么办?



谢谢。

解决方案

fn =


SERVER [' DOCUMENT ROOT'] '/ nink / hai.txt';


fh = 的fopen(

I'm writing a php script.
I want to open a file (if it doesn't exist, then create a new file) from my server and show the content in a textarea.

My code is,

<textarea name="text" rows="25" cols="100">
<?php

                $fn=$SERVER['DOCUMENT ROOT'] . '/nink/hai.txt';

                $fh=fopen($fn,"r");

                fclose($fh);

                echo file_get_contents($fn);

            ?>
</textarea>



When I reloaded the page the textarea is filled with,

<br />
<b>Warning</b>:  fopen(/nink/hai.txt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>/home/www/imwazir.net/nink/index.php</b> on line <b>23</b><br />
<br />
<b>Warning</b>:  fclose() expects parameter 1 to be resource, boolean given in <b>/home/www/imwazir.net/nink/index.php</b> on line <b>24</b><br />
<br />
<b>Warning</b>:  file_get_contents(/nink/hai.txt) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in <b>/home/www/imwazir.net/nink/index.php</b> on line <b>25</b><br />



I changed the permission of the "nink" folder even to 777, but still I'm getting the error.
What I did wrong ? What should I do ?

Thanks.

解决方案

fn=


SERVER['DOCUMENT ROOT'] . '/nink/hai.txt';


fh=fopen(


这篇关于使用php创建文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆