dongshou1991 2017-03-30 16:47
浏览 57

fopen()无法正常工作或显示错误

I want to create a new file along with the the creation of a record in my db. The db part works fine, but the file part isn't working. I want to create a file in another folder in the root directory and I used the same code with changes in the file name. Despite setting ini_set('display_errors',3) the code doesn't return any errors, I've also tried fopen($file_name,"w") or die("unable to open file"), still the code ran. I've given IIS_IUSRS full control over the directory. Here is my code

$data = mysqli_fetch_array(mysqli_query($conn,"Select * from content where link='$url'")); //fetch data from db
$id = $data['id'];
$file_name="/files/$id.html"; //sets file name
$file = fopen($file_name,"w"); //creates the file
fwrite($file,$_POST['desc']); //writes to the file
fclose($file); //closes the file
  • 写回答

1条回答 默认 最新

  • dragon456101 2017-03-31 05:14
    关注

    The problem was PHP wasn't going to the root directory. I added $root = $_SERVER['DOCUMENT_ROOT'] and replaced $file_name="/files/$id.html" with $file_name="$root/files/$id.html"; and it worked like a charm.

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备