dongshandun4363 2015-11-28 10:44
浏览 59
已采纳

在php中从admin创建新文件?

Hi i am reading a file in php from folder admin filename is createfile.php

and thencreating new file its working fine but when i crete new file its create in same folder admin please help to to soleve this problem how can i crete file out side folder or in root place.

File structure

 Admin--
                     |
                     |--createpage.php

Coode here:

creatpage.php

 $filename="demo";
$fs=fopen("createfile.php", "r");
$ft=fopen("$filename", "w");
if ($fs==NULL)
{
    echo "Can't Open Source File ...";
    exit(0);
}

if ($ft==NULL)
{
    echo "Can't Open Destination File ...";
    fclose ($fs);
    exit(1);
}

else
{
    while ($ch=fgets($fs))
        fputs($ft, $ch);

    fclose ($fs);
    fclose ($ft);
}

Please any one can help me Thanks

  • 写回答

1条回答 默认 最新

  • duanlu1279 2015-11-28 11:10
    关注

    You can create a new file in your root path like the below:

    $rootUrl = "your root url here";
    $fs=fopen($rootUrl."createfile.php", "w");
    

    Or if you want to create the file just outside Admin directory, you can use "../" like:

    $fs=fopen("../createfile.php", "w");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用