Files
Metadata_PHP/metadata/include/swfupload/upload.php
2020-02-27 00:28:43 +06:00

42 lines
1.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
function delPHPExt($fName)
{
$pos = strrpos($fName, '.')+1;
if(strtolower(substr($fName,$pos))=='php')
{
return substr($fName,0,$pos).'VIRUS';
}else {
return $fName;
}
}
$uploadDir = 'uploads/'; //папка для хранения файлов
$allowedExt = array('jpg', 'jpeg', 'png', 'gif');
$maxFileSize = 2 * 1024 * 1024; //1 MB
//если получен файл
if (isset($_FILES)) {
//проверяем размер и тип файла
$ext = end(explode('.', strtolower($_FILES['Filedata']['name'])));
if (!in_array($ext, $allowedExt)) {
return;
}
if ($maxFileSize < $_FILES['Filedata']['size']) {
return;
}
if (is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
$fileName = $uploadDir.$_FILES['Filedata']['name'];
//если файл с таким именем уже существует...
if (file_exists($fileName)) {
//...добавляем текущее время к имени файла
$nameParts = explode('.', $_FILES['Filedata']['name']);
$nameParts[count($nameParts)-2] .= time();
$fileName = $uploadDir.implode('.', $nameParts);
}
move_uploaded_file($_FILES['Filedata']['tmp_name'], delPHPExt($fileName));
echo '<img src="'.$fileName.'" alt="'.$fileName.'" />';
}
}