-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6.php
52 lines (51 loc) · 1.47 KB
/
6.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
function save_name($data){
return file_put_contents('name_image.txt',serialize($data));
}
function get_name(){
return unserialize(file_get_contents('name_image.txt'));
}
if (file_exists('name_image.txt')) {
$result = get_name();
}
@mkdir("gallery", 0777);
if(isset($_POST['submit'])){
$parts = explode(".", $_FILES['photo']['name']);
$graphics = ["jpg","png","gif","bmp"];
if(in_array($parts[count($parts)-1], $graphics))
{
$upload_dir = './gallery/';
$upload_file = $upload_dir . basename($_FILES['photo']['name']);
if (copy($_FILES['photo']['tmp_name'], $upload_file)){
echo "<h3>Файл успешно загружен на сервер</h3>";
$result[] = $_FILES["photo"]["name"];
save_name($result);
}
}
else
echo "Wrong file type";
}
?>
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>6</title>
</head>
<body>
<form action="6.php" method="post" enctype="multipart/form-data">
<label for="photo[]">Photo</label>
<input id="photo" type="file" name="photo">
<input type="submit" value="Загрузить" name="submit">
</form>
<?php if(file_exists('name_image.txt')): ?>
<table>
<?php foreach($result as $b): ?>
<tr>
<td>
<img src="<?php echo 'gallery' . DIRECTORY_SEPARATOR . $b; ?>"
</td>
</tr>
<?php endforeach ?>
</table>
<?php endif ?>
</body>