mac 下php运行bug

时间:2023-03-08 21:16:01
mac 下php运行bug

如下所说bug在window下没有,在mac下存在。

mac下的php报如下错误:

fopen("data.json") Error: failed to open stream: Permission denied

  网上找了原因,说是这个文件没有权限,但是我在文件右键,选择文件简介,里面显示有读写权限,很纳闷,但是运行 sudo chomd 777 data.json 。然后发现这个错误解决了。

但是又报如下错误:

Warning: Cannot modify header information - headers already sent by

  网上又查了一堆,发现是mac下php的header()原因。

mac下php文件 header() 报错,代码如下:

header('Location: ../main.php');

  好吧,那我就不用,header(),使用 js 代替页面重定向,代码如下:

echo "<script>window.location='../main.php'</script>";