dongmei8209 2019-07-13 02:22
浏览 95

为什么我不能写入文件?

I have to write the information I receive from a form in a text file, and this I tested locally and it worked.

$file = "data.txt";
$data = @fopen($file, "a");
//$data = @fopen("data.txt", "a");
@fwrite($data, "Number: " . $number . " |");
@fwrite($data, " Tittle: " . $tittle . " |");

But when I upload it to the server, the data is not written to the file. I have tried with this:

$data = @fopen("registers/data.txt", "a");
$data = fopen("registers/data.txt", "a");
$datos = fopen("./registers/data.txt", "a");

And nothing works.

In download.php I download the file and it does download correctly but without any information.

<?php
$file = "data.txt";

if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");

$type = filetype($file);
// Get a date and timestamp

// Send file headers
header("Content-type: $type");
header("Content-Disposition: attachment;filename=data.txt");
header("Content-Transfer-Encoding: binary"); 
header('Pragma: no-cache'); 
header('Expires: 0');
// Send the file contents.
set_time_limit(0); 
readfile($file);
?>

What can I do? I can't find a solution. Help me!

  • 写回答

1条回答 默认 最新

  • dpgui8229808 2019-07-13 10:38
    关注

    When fopen can't open the file, it returns false and a warning is emitted. You can show warnings by using error_reporting(E_ALL); at the beginning of your script.

    Your issue is probably related to file permissions. Make sure the webserver has write permissions to the file and its directory.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看