简体   繁体   English

不能写入文件PHP没有错误

[英]can't write into file php no error

I am trying to write data into a text file from php using fwrite or file_put_contents . 我正在尝试使用fwritefile_put_contents从php将数据写入文本文件。 Although both fwrite and file_put_contents return 20 indicating Write operation successful and that 20 bytes were written into the file, but i can't find anything in the file. 尽管fwritefile_put_contents返回20表示写操作成功,并且20字节已写入文件,但是我在文件中找不到任何内容。 What might be the issue?? 可能是什么问题?

  • My file is writable. 我的文件可写。
  • PHP is able to find my file. PHP能够找到我的文件。
  • I have even made the file wriable in $file_write_handle. 我什至在$ file_write_handle中使文件变得可写。

SO what is the problem here?? 那么这是什么问题呢?

<?php

$file_name = "user_notes.txt";

$file_write_handle = fopen($file_name,'w');

$data = " i am a disco dancer";

if(file_exists($file_name))
{
    echo "exist";   
}else{
    echo "absent";
}

echo "&nbsp";


if(is_writable($file_name))
{
    echo "writable";
}else {
    echo "cant write";
}

$fw=fwrite($file_write_handle, $data);
echo "fw result" . $fw . "<br/>";

$fpc=file_put_contents($file_name, $data);
echo "fpc result : " . $fpc;
fclose($file_write_handle);

?>

当我在本地服务器上工作并且文件正在写入并存储在服务器而不是本地计算机上时,问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM