开发者

$_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);

I also verified that $_POST["file"] was infact "USA"


$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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜