John Humphreys
John Humphreys

Reputation: 39224

When should I call rawurlencode and rawurldecode?

I'm writing a basic file browser in PHP as a homework assignment. I've got the whole thing working nicely and haven't really run into any problems - it's pretty simple. Open a directory, show directories and up-one-level as links, show files as plain-old-text.

I've read about rawurlencode and rawurldecode, and I was wondering when I should use them specifically, or if they're needed at all in this case.

Do PHP functions like opendir() work on encoded URLs, or should I decode URLs before passing them to the function?

Should I call rawurlencode() on the path I put in my hyperlinks to other directories?

Any suggestions are more than welcome, and let me know if I'm just barking up the wrong tree! :)

Upvotes: 2

Views: 444

Answers (1)

imm
imm

Reputation: 5919

If you're passing the directory path to open through the URL, then yes, it would be a good idea to use rawurlencode in that. Then use rawurldecode when passing the parameter to opendir. Or, before doing that, check that the directory exists first with is_dir.

Upvotes: 1

Related Questions