0

i have a download.php file which gets and opens files. i have a problem is that files were named using '&' in the file name so i get file not found when trying to access files with '&' in them.

example: download.phpf=one_&_another.pdf

in the download.php file i use get to the the file name ($_GET['f']) the example above throws the error file not found if i change the file name to one_and_another.pdf it works.

Yes renaming would be nice if there wasnt a whole lot of these files named this way.

I need to know how to ignore the fact that '&' doesnt mean im about to pass another var in php.

Shane
  • 1

3 Answers3

2

If you can control the query strings, you need to URL encode the ampersands so they look like this:

download.php?f=one_%26_another.pdf

Then look for $_GET['f'] as usual. Otherwise a literal ampersand & would break $_GET into

{ 'f' => 'one_', '_another.pdf' => '' }
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
1

You will probably just need to urlencode() the & properly in your links:

download.php?f=one_%26_another.pdf
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

Rule number 1 for accepting user input: do not trust it.

Refer to this StackOverflow answer for your solution.

Community
  • 1
  • 1
Dekker500
  • 821
  • 5
  • 7
  • Good advice and link, but he is not *trusting* the file name in question as such. He just has an encoding problem. Still, renaming them according to a better scheme is a option worth considering – Pekka Jan 13 '11 at 18:29