Dr. Andrew Besmer
input tag with a type attribute set to file<input type="file" name="yourUpload">
enctype needs to be setapplication/x-www-form-urlencodedmultipart/form-data$_FILESarray(1) {
["yourUpload"]=> array(5) {
[name] => 400.png
[type] => image/png
[tmp_name] => /tmp/php5Wx0aJ
[error] => 0
[size] => 15726
}
}
UPLOAD_ERR_OK or 0 - No errors presentUPLOAD_ERR_INI_SIZE or 1 - File size is greater than upload_max_filesize in php.iniUPLOAD_ERR_FORM_SIZE or 2 - File size is greater than MAX_FILE_SIZE in the HTML form; don’t trust this!UPLOAD_ERR_PARTIAL or 3 - File was only partially uploadedUPLOAD_ERR_NO_FILE or 4 - No file was uploadedUPLOAD_ERR_NO_TMP_DIR or 6 - Missing a temp directory to hold files while processingUPLOAD_ERR_CANT_WRITE or 7 - Permission error writing to tempUPLOAD_ERR_EXTENSION or 8 - A PHP extension stopped the file upload.png, .jpg, .pdf$_FILES["yourUpload"]["type"]
array(1) {
["yourUpload"]=> array(5) {
[name] => bad.php
[type] => image/png
[tmp_name] => /tmp/php5Wx0aJ
[error] => 0
[size] => 15726
}
}
finfo$finfo = new finfo(FILEINFO_MIME_TYPE);
$fileType = $finfo->file($_FILES['yourUpload']['tmp_name']);
submission.pdf1.png, 2.png, 3.png)b3088d04a5c6aba7.png)c553822654e4a60440e36f1a51a20edc.png)md5_file($filename)bin2hex(openssl_random_pseudo_bytes(8)); //16 chars
file_exists($filename)move_uploaded_file($temp, $path)
$_FILES
unlink($filename)