Created
May 17, 2012 14:54
-
-
Save h4/2719450 to your computer and use it in GitHub Desktop.
PHP. Загрузка файлов
This file contains hidden or 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
<!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