简体   繁体   中英

Can I move files to the private directory on a server using PHP?

Let's say I have the following path to my web files.

/home/user/username/public_html/domain.com

Can I run PHP script in /domain.com/script.php in browser (www.domain.com/script.php) that will move some files from this directory to /home/user/username/private and run the same script with GET parameters to move the data back to public?

Is it safe? Can I operate with files that are under the website path? How deep can I go?

Can you run the script to move files. Yes.

Moving them from private to public with GET parameters isn't ideal because anyone can access that url and make your private files public.

Ideally you would have an admin area of your website that requires a separate login for this.

The function you want is copy() or rename() which will copy and cut a file to a specific directory respectively

http://php.net/manual/en/function.copy.php

http://php.net/manual/en/function.rename.php

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