search
HomeBackend DevelopmentPHP Tutorialphp可以操作服务器根目录以外的路径吗

php可以操作服务器根目录以外的路径吗

php可以操作服务器根目录以外的路径吗?

具体问题:

php可以操作服务器根目录以外的路径么

比如f盘的一个文件夹

有办法么

回答:

windows 平台所谓的根目录可能是指的系统目录,或者盘符目录。

UNIX以及Linux/GNU系统中根目录特指 Root directory及'/'

以上不深究,我们讨论你提出的问题。

分割线

PHP是一种解释性语言。解释性语言程序是不需要编译的,运行程序时才需由PHP解释器即时编译。这里不要有疑问,php解释器自然是包含在php包内(不细解释,有时间去翻翻资料)。我们在本地解释php语言是没任何用途的,用php自然是要他的特长做web开发。那我们就需要一款web服务器软件来驱动php解释器,好让浏览器与服务器之间形成HTTP协议通信。

PHP支持的web服务器软件很多:Apache、Nginx、Microsoft Internet Information Server(IIS)、Personal web Server(PWS)、Netscape 、iPlant server、Oreilly Website Pro Server、Caudium、Xitami、OmniHTTPd 等等等。这里我们选最熟悉的Apache来举例。

我们可以配置php在Apache作为CGI脚本或者是apache模块或者fastcgi模式来运行。默认的,比如在windows平台基本是作为apache模块来运行。竟然是Apache运行解释器,那自然我们用php语言来增删改文件都属于apache用户身份去执行。

比如apache 配置用户和用户组都是www/www.(网络上有金步国翻译的apache手册,有兴趣可以Google一下)。

windows平台(很多年不使用它了,如果解释有误请包含)

FAT32分区模式下,windows上是无文件权限这个说法的。自然不管是php是放置在哪个盘。只要是系统能访问的盘符,php都能创建文件或者文件夹。

NTFS分区,已经引入文件权限。这里就需要辨别apache用户在要操作的目录下有无权限,如果无则不能产生动作。

UNIX、linxu/GNU

优秀的文件系统权限设计。除了基本的 读 写 执行 权限还能定义隐藏属性和文件特殊权限等等。以及linux的使用者管理建立用户和用户组。如此我们就要遵循文件权限以及用户权限去应用php动作。具体的可以在google搜索详细了解。Linux 文件权限|linux 账号与用户组。

分割线

权限部分,我就不解释了。基本上你需求的深层次点的原理已经基本完整。

更多相关技术文章,请访问PHP中文网

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

What is the importance of setting the httponly flag for session cookies?What is the importance of setting the httponly flag for session cookies?May 03, 2025 am 12:10 AM

Setting the httponly flag is crucial for session cookies because it can effectively prevent XSS attacks and protect user session information. Specifically, 1) the httponly flag prevents JavaScript from accessing cookies, 2) the flag can be set through setcookies and make_response in PHP and Flask, 3) Although it cannot be prevented from all attacks, it should be part of the overall security policy.

What problem do PHP sessions solve in web development?What problem do PHP sessions solve in web development?May 03, 2025 am 12:02 AM

PHPsessionssolvetheproblemofmaintainingstateacrossmultipleHTTPrequestsbystoringdataontheserverandassociatingitwithauniquesessionID.1)Theystoredataserver-side,typicallyinfilesordatabases,anduseasessionIDstoredinacookietoretrievedata.2)Sessionsenhances

What data can be stored in a PHP session?What data can be stored in a PHP session?May 02, 2025 am 12:17 AM

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

How do you start a PHP session?How do you start a PHP session?May 02, 2025 am 12:16 AM

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

What is session regeneration, and how does it improve security?What is session regeneration, and how does it improve security?May 02, 2025 am 12:15 AM

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor