doutaoer3148 2013-12-18 08:13
浏览 65

无法使用PHP创建HTML文件

I'm trying to create an .html file using PHP, and filling it with the content of an array, but I can't create the html file. Here's my function:

function viewPag(){
    session_start();

    $handler=fopen("view.php", 'w+');

    for ($i=0; $i < count($_SESSION["Text"]); $i++) { 
        fwrite($handler,$_SESSION["Text"][$i]);
    }

    fclose($handler);

    header("Location: view.php");
}
  • 写回答

2条回答 默认 最新

  • doujinge9648 2013-12-18 08:21
    关注

    It's possible that you are not on the folder you think. use echo getcwd(); to print the current folder, and then use a relative path to store the file where you want.

    It also may be that your fopen call is failing due to permission issues. Add an if to test the $handler value after the fopen call:

    if (!$handler) {
        echo "Could not open file for writing. Aborting";
        die();
    }
    

    And one thing you should really do is look at your logs and search for errors. Withouth looking at the logs you (and we) are just blind and don't know what is failing (maybe what fails is something before this function... we can't know for sure).

    评论

报告相同问题?

悬赏问题

  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机