简体   繁体   中英

Create folder outside public_html to upload files

I creating script and I need to let users upload files (images) . and for security reasons I want to make file folder outside public_html .

But my problem is maybe my potential customers may have different folders structure in their servers.

So my question is : There is a way in php to go back one folder before public_html ?

Another possible case if my client put script file in directory like that public_html/demo/ , so in that case I need to go 2 folders back.

I try to use $_SERVER["DOCUMENT_ROOT"] but it give the public server directory.

any help or suggestion will be helpfull. thank you

If the php user has the permission to do so, you should be able to include/write files to a directory using a relative path for example:

include("../test.php");

Likewise if you had a directory which was writable by the php user you should be able to create files in that directory also using a relative path:

$ cat test1.php
<?php

    $file = fopen("../test.php", "w");
    fwrite($file,  "Hello World. Testing!\n");
    fclose($file);
    include("../test.php");


$ php test1.php
Hello World. Testing!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM