0

when upload files, I make something like 'preview'. It stores form variables as

for(i=0;i<count($UpFile);i++){ //loop
<input name="Files[',htmlspecialchars($UpFile_name[$i]),'][FileName]" type="text" value="',htmlspecialchars($UpFile_name[$i]),'">
<input name="Files[',htmlspecialchars($UpFile_name[$i]),'][FileSize]" type="text" value="',htmlspecialchars($UpFile_size[$i]),'">

and then after submittting, when $Files is array I work with saved files, using their names as variables names.

The issue is, when I upload file with the name file[123].jpg, then php look at it not as $Files['file[123].jpg'], but as $Files[$file[123].jpg']. In other words, form record not found.

How to store names for form inputs to preserve square brackets, if there're ones in filenames?

el Dude
  • 5,003
  • 5
  • 28
  • 40

1 Answers1

0
$SpecReplace=Array('['=>'&#91;',']'=>'&#93;');
<input name="Files[',htmlspecialchars(strtr($UpFile_name[$i],$SpecReplace)),'][FileName]" type="text" 

replacing brackets to html special chars helped =)

el Dude
  • 5,003
  • 5
  • 28
  • 40