1
I need to import data xlsx to a system I created.
HTML
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="arquivo">
<input type="submit" name="pegar value="pegar">
</form>
PHP
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
if (isset($_POST['pega'])) {
$arquivo = $_FILES['arquivo'];
$file = fopen($arquivo,"r");
while(! feof($file)){
echo fgets($file). "<br />";
}
fclose($file);
}
And these are the error messages that appear:
Warning: fopen() expects Parameter 1 to be a Valid path, array Given in /Applications/MAMP/htdocs/sistemas/scripts_da_web/php/importaCSV.php on line 20
Warning: feof() expects Parameter 1 to be Resource, Boolean Given in /Applications/MAMP/htdocs/sistemas/scripts_da_web/php/importaCSV.php on line 22
Warning: fgets() expects Parameter 1 to be Resource, Boolean Given in /Applications/MAMP/htdocs/sistemas/scripts_da_web/php/importaCSV.php on line 24
Upload the file before opening, then you delete it with
unlink()
– rray
Sorry @rray, I don’t understand. Upload before?
– GustavoSevero
Yes, use
move_uploaded_file
, remember that$_FILES
is an array, of aprint_r()
to see the information contained in it.– rray
With print_r() appeared this: Array ( [name] => VP 1015.xlsx [type] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [tmp_name] => /Applications/MAMP/tmp/php/phpCIgXr7 [error] => 0 [size] => 76347 )
– GustavoSevero
Can someone please help me?
– GustavoSevero