files

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package files provides the filesystem shims phpscript exposes to PHP: path helpers, reads, writes, streams, and the uploaded-file functions that go with $_FILES. They are grouped here rather than in stdlib because they are the one part of the standard library bound to a directory on the host, and because a host that runs untrusted scripts may want to leave them out.

Go's fs.FS is read-only, so writes (fopen/fwrite/mkdir) use the os package against the same root; the runner's include resolution still uses the fs.FS abstraction passed to runner.New.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(rt *runner.Runtime)

Register installs the filesystem shims rooted at the process working directory. A host serving scripts out of a project directory binds that instead, with RegisterRoot.

func RegisterRoot

func RegisterRoot(rt *runner.Runtime, dir string)

RegisterRoot installs the filesystem shims rooted at dir. A relative path from PHP resolves against dir and cannot climb out of it; an absolute path is taken as the script wrote it and is not confined.

Writes are held to the runtime's writable_paths when it configures any, which is what confines an absolute path: naming one does not make it writable.

It replaces whatever root was installed before it, so a host calls it after stdlib.Register (stdlib.RegisterFS does exactly that).

func Within

func Within(name, dir string) bool

Within reports whether name is dir or something beneath it. The separator is what keeps a sibling out: /srv/site/uploads-old is not under /srv/site/upload even though the string starts the same way.

It is exported because a host has the same question to answer: a server that serves a writable directory has to know not to execute the PHP a script may have written into it.

func WritableRoots

func WritableRoots(dir string, paths []string) []string

WritableRoots resolves the configured writable_paths against the directory the shims are bound to. An entry is a path inside the project, so uploads is the project's uploads directory and public/uploads is the one below the document root; an absolute entry is taken as given, for a host that writes somewhere outside its own tree on purpose.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL