1+ <?php
2+ session_start ();
3+ $ username = 'vue ' ;
4+ $ password = '123456 ' ;
5+ $ _SESSION ['message ' ] ='' ;
6+ if ($ _SERVER ['REQUEST_METHOD ' ] == 'POST ' && isset ($ _POST ) && isset ($ _POST ['logout ' ])) {
7+ session_destroy ();
8+ header ('Location: ' . $ _SERVER ['REQUEST_URI ' ]);
9+ die ();
10+ }
11+ if (isset ($ _POST ) && isset ($ _POST ['username ' ]) && isset ($ _POST ['password ' ]))
12+ {
13+ if ($ _POST ['username ' ] == $ username && $ _POST ['password ' ] == $ password ){
14+ $ _SESSION ['username ' ] = $ username ;
15+ } else {
16+ $ _SESSION ['message ' ] ='Username or password is wrong ' ;
17+ }
18+ }
19+
20+ if (isset ($ _POST ) && isset ($ _FILES ['zip ' ]))
21+ {
22+ if ($ _SESSION ['username ' ] != $ username ){
23+ session_destroy ();
24+ $ _SESSION ['message ' ] ='You are not allowed to upload ' ;
25+ }
26+
27+ $ target_Path = __DIR__ .'/ ' .basename ( $ _FILES ['zip ' ]['name ' ] );
28+ if (move_uploaded_file ($ _FILES ['zip ' ]['tmp_name ' ], $ target_Path )){
29+ $ _SESSION ['message ' ] ='Something wrong happened ' ;
30+ };
31+
32+ $ zip = new ZipArchive ;
33+ if ($ zip ->open ($ target_Path ) === true ) {
34+ $ zip ->extractTo (__DIR__ );
35+ $ zip ->close ();
36+ $ _SESSION ['message ' ] ='Unzipped Process Successful! ' ;
37+ unlink ($ target_Path );
38+ } else {
39+ $ _SESSION ['message ' ] = 'Unzipped Process failed ' ;
40+ }
41+ }
42+
43+
44+ if (!empty ($ _SESSION ['message ' ])){
45+ echo "<p class='message'> " .$ _SESSION ['message ' ]."</p> " ;
46+ }?>
47+
48+
49+ <?php if (! isset ($ _SESSION ['username ' ])) { ?>
50+ <div class="container">
51+ <h3>Login</h3>
52+ <form class="form-container" action="" method="post">
53+ <label>
54+ <input placeholder="username" class="form-control" type="text" name="username">
55+ </label>
56+ <label>
57+ <input placeholder="password" class="form-control" type="password" name="password">
58+ </label>
59+ <button class="submit-button" type="submit" >login</button>
60+ </form>
61+ </div>
62+
63+ <?php } ?>
64+
65+ <?php if (isset ($ _SESSION ['username ' ]) && $ _SESSION ['username ' ] == 'vue ' ) {?>
66+ <form method="POST">
67+ <input type="hidden" name="logout" value="logout">
68+ <button class="logout">Logout</button>
69+ </form>
70+ <div class="container">
71+ <h3>Zip Uploader</h3>
72+ <form class="form-container" action="" method="post" enctype="multipart/form-data">
73+
74+ <div class="custom-file">
75+ <label for="customFile">Choose file ...</label>
76+ <input type="file" name="zip" class="form-control" id="customFile">
77+ </div>
78+
79+ <button type="submit" class="submit-button">upload</button>
80+
81+ </form>
82+ <div class="footer">
83+ <p>Developed in <a target="_blank" href="http://shetabit.com">Shetab</a> group</p>
84+ </div>
85+ </div>
86+
87+ <?php } ?>
88+ <style>
89+ * {
90+ font-family: monospace;
91+ }
92+
93+ .form-container {
94+ display: flex;
95+ margin: auto;
96+ flex-direction: column;
97+ width: 50%;
98+ justify-content: center;
99+ height: 30%;
100+ }
101+
102+ @media only screen and (max-width: 600px) {
103+ .form-container {
104+ width: 90%;
105+ }
106+
107+ .container > h3 {
108+ font-size:50px!important;
109+ }
110+ }
111+ .submit-button {
112+ background: sandybrown;
113+ color: #000111;
114+ padding: 10px 0px;
115+ border: none;
116+ outline: none;
117+ box-shadow: 0px 0px 6px -1px #4c1010;
118+ border-radius: 8px;
119+ cursor: pointer;
120+ transition: 0.3s all;
121+ }
122+
123+ .submit-button:hover {
124+ background: #efac70;
125+ box-shadow: 0px 0px 6px 0px #561616;
126+ }
127+
128+ .form-control {
129+ margin: 10px 0px;
130+ border-radius: 5px;
131+ outline: none;
132+ width: 100%;
133+ min-height: 40px;
134+ border: solid 1px #d7eada;
135+ transition: border 150ms;
136+ }
137+
138+ .form-control:focus {
139+ border: solid 2px #487051;
140+ }
141+
142+ .container {
143+ padding-right: 40px;
144+ padding-left: 40px;
145+ }
146+
147+ .footer {
148+ background: #8fd19e;
149+ position:fixed;
150+ bottom: 0;
151+ left: 0;
152+ right: 0;
153+ }
154+ .footer p {
155+ text-align: center;
156+ }
157+
158+ .container > h3 {
159+ margin-top: 60px;
160+ text-align: center;
161+ font-size: 100px;
162+ }
163+
164+ .message {
165+ color: #f10000;
166+ position: absolute;
167+ top: 10px;
168+ left: 0;
169+ right: 0;
170+ text-align: center;
171+ }
172+ .logout {
173+ position: absolute;
174+ top: 0;
175+ left: 0;
176+ background: sandybrown;
177+ color: #000111;
178+ padding: 10px 10px;
179+ border: none;
180+ outline: none;
181+ box-shadow: 0px 0px 6px -1px #4c1010;
182+ border-radius: 0px 0px 8px 0px;
183+ cursor: pointer;
184+ transition: 0.3s all;
185+ }
186+
187+ .logout:hover {
188+ padding: 13px 13px;
189+ background: #efa86b;s
190+ box-shadow: 0px 0px 6px 0px #4c1010;
191+ }
192+ </style>
0 commit comments