0

I am using a PHP GET method to grab a file name that then is placed in a get_file_contents command. If it is possible, I would like to ignore letter case so that my URL's are cleaner.

For instance, example.com/file.php?n=File-Name will work but example.com/file.php?n=file-name will not work using the code below. I feel like this should be easy but I'm coming up dry. Any thoughts?

$file = $_GET['n'];
$file_content = file_get_contents($file); 
internetjason
  • 81
  • 1
  • 9

2 Answers2

0

Lowercase all your filenames and use:

file_get_contents(strtolower($file));

(I hope you're aware of some of the risks involved in using this.)

Community
  • 1
  • 1
Sherlock
  • 7,525
  • 6
  • 38
  • 79
  • There is an iOS app that is uploading these files for me, so I cannot have them changed to lowercase. I was hoping to figure out a workaround. – internetjason Oct 08 '14 at 13:26
0

The Linux filesystem is case sensitive. If you want to do case insensitive matching against files that already exist on the user's machine, your only option is to obtain a directory listing and do case-insensitive comparison.

But you don't explain where the download URLs come from. If you already know the correct filenames and you want to generate prettier URLs, you can keep a list of the true pathnames and look them up when you receive a case-normalized one in a URL (you could even rename them completely, obfuscate, etc.)

alexis
  • 48,685
  • 16
  • 101
  • 161