Last active
February 22, 2018 18:26
-
-
Save Sentinel17/ea0cf9b9ab1c1e8078646c909548da1f to your computer and use it in GitHub Desktop.
Домашнее задание №6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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