How to open a file from php code inside an html file

I have a .html file and inside it I am running php code. PHP code should open the .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> 

Every time I get this error message: Could not open filename.ini file !!!!

File

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

I have full control over this .ini file.

Any suggestions?

+5
source share
4 answers

Please check the file resolution; it may not be available to everyone.

run "chmod 666 filename.ini"

0
source

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

+1
source

Try the following:

 $fp = fopen (__DIR__ . "/filename.ini", "r"); 

See the list of magic constants: http://php.net/manual/en/language.constants.predefined.php

0
source

Just get the contents of the INI file with an Ajax request.

no PHP code needed for Run file.

PHP script will now work with .htm or .HTML files.

0
source

Source: https://habr.com/ru/post/1243047/


All Articles