<?php
$valid_types = array('pdf', 'doc', 'xls', 'jpg', 'png');
if (isset($_FILES['userfile'])) {
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$filename = basename($_FILES['userfile']['name']);
$ext = substr($_FILES['userfile']['name'], 1 + strrpos($_FILES['userfile']['name'], '.'));
if(in_array($ext, $valid_types)) {
$uploaddir = '/var/www/html/public/a-level-homework/Dz_4/img/';
$uploadfile = $uploaddir . $filename;
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
echo "<img src='img/$filename' alt='$filename' title='$filename' />";
}
else{
echo "Данный тип файла загрузить нельзя";
}
}}
?>
<form action="<?= $_SERVER['SCRIPT_NAME']?>" enctype="multipart/form-data" method="post">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>