Форма загрузки файла - ОШИБКА Undefined array key
Primary tabs
index.html
<html> <head> <title>Text field</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h1>Open your file</h1> <form enctype="multipart/form-data" method="post" action="phptext.php"> <input type="file" name="userfile"> <input type="submit" value="load"> </form> </body> </html>
phptext.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Read from textarea</title> </head> <body> <h1>Show your file</h1> <br> <?php $file = fopen($_REQUEST["userfile"]["name"], "r"); while(! feof($file)) { $line = fgets($file); echo $line. "<br>"; } fclose($file); ?> </body> </html>
Ошибка
Warning: Undefined array key "userfile" in /var/www/projectForms/phptext.php on line 11
Warning: Trying to access array offset on value of type null in /var/www/projectForms/phptext.php on line 11
Fatal error: Uncaught ValueError: Path cannot be empty in /var/www/projectForms/phptext.php:11 Stack trace: #0 /var/www/projectForms/phptext.php(11): fopen() #1 {main} thrown in /var/www/projectForms/phptext.php on line 11
- Log in to post comments
- 2259 reads
Gurgen
Thu, 12/09/2021 - 22:07
Permalink
Ошибка заключается в том, что
Ошибка заключается в том, что нужно использовать не массив
а
. И в ф-цию fopen передавать не ["name"] (имя файла), а путь ["tmp_name"].