Skip to content

Instantly share code, notes, and snippets.

@h4
Created May 17, 2012 14:54
Show Gist options
  • Save h4/2719450 to your computer and use it in GitHub Desktop.
Save h4/2719450 to your computer and use it in GitHub Desktop.
PHP. Загрузка файлов
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="myfile" >
<input type="submit" value="Отправить">
</form>
</body>
</html>
<?php
if (isset($_FILES['myfile'])) {
foreach ($_FILES['myfile'] as $key => $value) {
echo "$key: $value <br/>";
}
}
function save_file($formfilename) {
$tmp_name = $_FILES[$formfilename]['tmp_name'];
$file_name = $_FILES[$formfilename]['name'];
if(is_uploaded_file($tmp_name)) {
echo "<p>Файл загружен</p>";
if(file_exists($file_name)) {
echo "<p>Такой файл уже есть";
} else {
if(copy($tmp_name, $file_name)) {
echo "<p>Файл скопирован";
} else {
echo "<p>Не удалось сохранить файл";
}
}
} else {
echo "<p>We have troubleds";
}
}
save_file('myfile');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment