Первая копия
This commit is contained in:
41
metadata/include/swfupload/upload.php
Normal file
41
metadata/include/swfupload/upload.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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.'" />';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user