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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?