-1
Hello I’m starting to learn PHP, and I created an HTML input that receives a TXT file that should be read in PHP but I’m having difficulties in reading the input file, which returns me the following error:
Warning: fopen(teste.txt): failed to open stream: No such file or directory in C:\Apache2\htdocs\teste.php on line 8
I wonder how I can solve?
My code is: (index.php)
<html>
<body>
<form action="teste.php" method="post">
<label for="myfile">coloque seu arquivo:</label>
<input type="file" id="myfile" name="myfile"><br><br>
<input type="submit" value="Submit">
</form>
(php test.)
<html>
<body>
Arquivo txt: <?php echo $_POST["myfile"]; ?><br>
<?php
$input_txt =$_POST["myfile"];
// Abre o Arquvio no Modo r (para leitura)
$arquivo = fopen ($input_txt, 'r');
?>
</body>
</html>
The
fopen
would only work if the file was already saved in the project directory. You need to get the file data from $_FILES.– Gnomo Escalate
And you’d have some clue how I can do that?
– user198451
I posted the answer below
– Gnomo Escalate