Since your $_FILES
is empty, here is a checklist for upload of files with PHP
On the server:
Verify in your php.ini
whether the following directives have these values:
file_uploads = On
post_max_size = 100M
upload_max_filesize = 100M
Beware of common errors when setting up the unit of size. Note above that it is 100M
and not 100MB
Make sure you're editing php.ini
right. After saving the options and restarting the server check through a phpinfo () if the values defined are the ones you defined
You may need a .htaccess
or .user.ini
file if you are using a shared server where you would not have access to 'php.ini
Ensure that your temporary files directory, set in the upload_tmp_dir
of php.ini
directive, and the directory in which you are going to write the uploaded files have the required read and write permissions set
Such directories can not have spaces like /tmp/my uploads
It is very rare, especially in your case with small files, but a comment, now extinct, in the PHP Manual, was directed to make sure that there is enough disk space for the operation
As for HTML:
Make sure your form has the enctype="multipart/form-data"
attribute.
GET requests do not support uploads with multipart/form-data
, so your forms must be set with method="POST"
This attribute must be in the <form>
tag (s) and surrounded by quotes and not backticks that some editors end up accidentally converting.
Make sure you do not have two or more <input type="file" />
with the same value for the name
attribute. If you need multiple uploads, add a couple of brackets to the end of the name:
<input type="file" name="files[]">
<input type="file" name="files[]">
Although obvious, the name
attribute must be present in all fields that must be processed
Remember to close all <form>
tags on your page with the </form>
counterpart
Make sure you are not nesting forms:
<form><form></form></form>
And no overlapping tags:
<div><form></div></form>
Last, but not least, check that there is no JavaScript disabling the submission of the form or removing the <input type="file">
element
Regarding the end user:
Make sure the file being uploaded does not have any non-alpha characters in it
If you are uploading "asynchronous" JavaScript should obviously be enabled
What about the programmer?
Well, you're getting an undefined E_NOTICE index so you should check if that index exists.
Give a var_dump () / print_r () in $ _FILES and see the structure of the superglobal. Is it REALLY one-dimensional?
Quite common in multiple uploads, suddenly what you use as $_FILES['arquivo']['name']
may have an additional numeric index
Resolved the case, to get the file extension you can do with pathinfo () , as you are already doing, but add the default constant PATHINFO_EXTENSION as already suggested.
Just note that if the path to be parsed ends with a dot (which for all intents and purposes is a file without a valid extension), pathinfo () will return an empty string, but if the file does not have any extension it will return NULL.
So be careful;)
Another option would be simple string manipulation:
$ext = ltrim( substr( __FILE__, strrpos( __FILE__, '.' ) ), '.' );
If there is a dot in the string, it returns the value after it, backwards.
If it does not, it returns the string itself, since strrpos () will fail and cast automatic PHP will make substr () consider this "failure" as zero and this causes the substring to start from the beginning.