I am new to PHP and am following a tutorial on YouTube. I have everything working in this file, except for the file uploading, any help would be appreciated. Here is the e
For uploading files, you must use the enctype in form tag.
<form enctype="multipart/form-data" action='register.php' method='post'>
this is a 1 year ago Post but you may still interested .. Check this option in PHP.ini : enable_post_data_reading=off It should be : on otherwise the $_FILES will be empty forever Whether PHP will read the POST data This option is enabled by default. Most likely, you won't want to disable this option globally. It causes $_POST and $_FILES to always be empty.
first: try to strict programming
error_reporting(E_ALL | E_STRICT);
also you must use isset for check is index for array available or not
if (isset($_POST['submitbtn']) && isset($_FILES['avatar'])) {
// ...
}
also check php configuraion
file_uploads "1"
upload_max_filesize "2M"
post_max_size "8M"
max_file_uploads 20
post max size must be larger than upload max file size.
also as guys said check form enctype
You should add form attribute enctype="multipart/form-data"
to upload files