1

I'm experienced with php but I'm a novice to the php source and php extensions. I want to extend php so that it randomly chooses an upload_tmp_dir from an array, rather than one fixed dir.

It doesn't look like php and the ini-file reading code has any natural ability to parse arrays in the ini file.

Is there any existing code or extension (either in the tree or outside it) that allows for mapping an ini-defined array to a global array val in php?

Otherwise I guess I'll introduce ini vals like "num_upload_dirs" and then "upload_tmp_dir_1" and "upload_tmp_dir_2" etc. and then explicitly check for all vals.

OR write the line-parsing and global-array-creating routines myself into the ini-file reader. Neither are very appealing. Any other suggestions?

Charles
  • 50,943
  • 13
  • 104
  • 142
cjp
  • 313
  • 1
  • 8

2 Answers2

0

The ini file format doesn't support arrays.

You will be best served by doing uplaod_tmp_dir_1 etc. You get no benefit from using array syntax.

It is actually fewer bytes if you think about it. ;)

Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
  • Thanks. I think you're right. Arrays are more natural to maintain, though, so the maintainer doesn't have to create indexes themselves. – cjp Jan 28 '11 at 00:17
  • To the down-voter: I am aware `parse_ini_file` will handle arrays. I was speaking to the low level c code which lacks the syntactic sugar of php source. – Byron Whitlock Jan 28 '11 at 00:24
0

PHP supports arrays in ini files by default. There is no need to patch anything

The ini

key[] = value1
key[] = value2

with this php

var_dump(parse_ini_file('my.ini'));

returns

array(1) {
  ["key"]=>
  array(2) {
    [0]=>
    string(6) "value1"
    [1]=>
    string(6) "value2"
  }
}
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • this question is about php source and extending php itself to change how it uses upload_tmp_dir. It looks like you're talking about interpreted .php code... by the time it comes to interpreting .php code the upload tmp location is fixed, that's why I need to change php source. – cjp Jan 28 '11 at 00:12
  • Read it some more times and I think you are right. I thought its about "arrays in inis" in general. I dont found a way to change this directory at runtime (it were to late anyway, the file is already uploaded), so: yes, right, answer is obsolete. – KingCrunch Jan 28 '11 at 00:21