Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open file from php code inside html file

Tags:

html

php

ini

I have ".html" file and inside it I run php code. The php code should open ".ini" file.

".ini" file:
blast+: blast+\bin

blastn: test_na_db => Nucleotide test database
blastp: test_aa_db => Protein test database
blastx: test_aa_db => Protein test database
tblastn: test_na_db => Nucleotide test database
tblastx: test_na_db => Nucleotide test database


".html" file:
<td valign=top>&nbsp;&nbsp;&nbsp;Database(s)</td>
<td>
<?php
$fp = fopen ("./filename.ini", "r");
if(!$fp) {
    echo "<p><strong> Error: Couldn't open file filename.ini </strong></p></body></html>";
    exit;
}
while(!feof($fp)) {
    $blastdbstring = rtrim(fgets($fp));
    if (!$blastdbstring) {
        continue;
    }
    if (!preg_match("/^\s*#/", $blastdbstring)) {
        $blastdbArray = preg_split('/:/', $blastdbstring);  
        $blastProgram = $blastdbArray[0];
        $dbString = $blastdbArray[1];

        if ($blastProgram == "blast+") {
            echo "<input type='hidden' name= 'blastpath' value='$dbString'>";
        }else {
            if (preg_match("/^\s*(.*?)\s*$/", $blastProgram, $match)) {
                $blastProgram = $match[1];
            }
            if (preg_match("/^\s*(.*?)(\s*|\s*,\s*)$/", $dbString, $match)) {
                $dbString = $match[1];
            }
            $dbString = preg_replace("/\s*=>\s*/", "=>", $dbString);
            if (preg_match("/,/", $dbString, $match)) {
                $dbString = preg_replace("/\s*,\s*/", ",", $dbString);
            }       
            echo "<input id='$blastProgram' type='hidden' name='blastdb[]' value='$dbString'>";
        }
    }   
}
fclose($fp);

?>
<select id="dbList" size=4 multiple="multiple" name ="patientIDarray[]">
<script type="text/javascript">
    here call js function that create options depend on the selection of previous question
</script>

</select>
</td>

Each time I got this error message: Couldn't open file filename.ini!!!!

".html" file and ".ini" file are in the same directory.

I have full control on that ".ini" file

Any suggestions?

like image 466
Reem Avatar asked Nov 08 '22 20:11

Reem


1 Answers

You probably want to use parse_ini_file

// Parse without sections
$ini_array = parse_ini_file("sample.ini");
print_r($ini_array);

// Parse with sections
$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_array);

http://php.net/manual/en/function.parse-ini-file.php

like image 116
reinierkors Avatar answered Nov 14 '22 23:11

reinierkors