Skip to content

Instantly share code, notes, and snippets.

@Sentinel17
Last active February 22, 2018 18:26
Show Gist options
  • Save Sentinel17/ea0cf9b9ab1c1e8078646c909548da1f to your computer and use it in GitHub Desktop.
Save Sentinel17/ea0cf9b9ab1c1e8078646c909548da1f to your computer and use it in GitHub Desktop.
Домашнее задание №6
<form action="upload.php" method="POST" enctype="multipart/form-data" target="frame">
<input type="file" name="file"><br><br>
<input type="file" name="file1"><br><br>
<input type="submit" value="Отправить">
</form>
<iframe name = "frame" id="frame" style="width:1000px; height:700px"></iframe>
<pre>
<?php
ini_set('display_errors',1);
foreach($_FILES as $key=>$value){
$file = $_FILES[$key];
$destination = $_SERVER['DOCUMENT_ROOT']. '/upload';
$fileName=explode('.',$file['name']);
$fullFileName=$destination.'/'.md5(microtime().rand()).'.'.$fileName[count($fileName)-1];
$file_size = $file['type'];
$typeFiles = ['image/jpeg', 'image/png'];
if($fileSize > 10000000) {
echo 'Слишком большой файл';
} else {
if(array_search($file['type'], $typeFiles)){
if(is_uploaded_file($file['tmp_name'])){
if(move_uploaded_file($file['tmp_name'], $fullFileName)){
echo 'Файл отправлен';
} else {
echo 'Не удалось отправить файл';
}
}
} else {
echo 'Тип файла не совпадает';
}
}
}
?>
</pre>
<img src="/upload/<?php echo basename($fullFileName) ?>">
<ul>
<li>Размер файла: <?php echo $file['size'] ?> байт</li>
<li>Имя до загрузки: <?php echo $file['name'] ?></li>
<li>MIME-тип: <?php echo $file['type'] ?></li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment