$_POST + fopen not working!
So this is fairly weird experience i have had over the last hour.
Say i have a data source that is controlled by a select
$fileName = "../data/".$_POST["file"];
$fh = fopen($fileName);
There is a f开发者_Python百科ile named "USA" in the data folder. When the select option starts, jQuery sends this to a PHP file which will open the proper file and get the correct contents out of file and put them into a different select statement. This does not work (Failed to open the stream error happens) But thats not the weird part. The weird part is if i use an absolute name rather than post such as...
$fileName = "../data/USA";
$fh = fopen($fileName);
$file = trim($_POST["file"]);
$fileName = "../data/".$file;
$fh = fopen($fileName, "r");
The <select>
needs to have a name:
<select name="file">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
I don't see any in your example. $_POST['file']
will get the value from the <option value="1">
If it still not working add var_dump($_POST["file"]);
and see what's in there. It should give you something like that string(1) "USA"
精彩评论