Menu

1 / 2

Sanitising video titles into filenames: the 255-byte limit and non-ASCII edge cases

DEV Community: php·Mobeen Ahmed·3 days ago
#XDnoLu4E
#devto#dev#title#name#filename
Long article (610 words) — no AI summary yet.
Reading 0:00
15s threshold

When someone downloads a video from ramrom.io , the file they save needs a name, and the obvious choice is the video's own title. It sounds trivial until the first title arrives with emoji, Arabic script, a colon, and 200 characters of hashtags. A filename that works on my server has to work on the visitor's phone too, and those two machines do not agree on what a safe name looks like.

The first rule I learned is that the title is user input, no matter where it came from. It may have been typed by the uploader, pasted from a translation tool, or pulled from a provider's API, and in every case I treat it as untrusted. A title can contain slashes, which on Linux mean directories; it can contain .. , which means parent directories; and on Windows it can contain characters like : and ? that are simply illegal in a filename. My sanitiser strips or replaces the lot: slashes and backslashes become dashes, control characters are dropped, and a ..…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.