php

간이 웹하드

장곰부대 2018. 3. 27. 17:10

webhard.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
<form enctype='multipart/form-data' action='upload.php' method='post'>
  업로드 할 파일을 선택하세요.<br>
  <input name='upload_file' type=file><br>
  <input type=submit value='업로드'>
</form>
 
 
<table width=800>
  <tr bgcolor=cyan align=center>
    <th>파일명</th><th>크기</th><th>업로드</th>
  </tr>
<?php
  $mysqli = new mysqli('localhost:3307','phpuser','1234','phpuser_db');
  if($mysqli->connect_errno){
    die("Failed connect to mysql server : (".$mysqli_errno.") ".$mysqli_error);
  }
 
  $sql = "select * from webhard order by binary(fname)";
  $result = $mysqli->query($sql);
 
  while($row=$result->fetch_row())
  {
    echo "<tr>";
    echo "<td><a href='upload/$row[1]'>$row[1]</a></td>";
    echo "<td align=right>$row[2]&nbsp</td>";
    echo "<td align=center>$row[3]</td>";
    echo "</tr>";
 
  }
  $result->free();
  $mysqli->close();
 
 ?>
 
cs


upload.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
<?php
if (move_uploaded_file($_FILES['upload_file']['tmp_name'],"upload/".$_FILES['upload_file']['name'])){
  $mysqli = new mysqli('localhost:3307','phpuser','1234','phpuser_db');
  if($mysqli->connect_errno){
    die("Failed connect to mysql server : (".$mysqli_errno.") ".$mysqli_error);
  }
 
  $fname = $_FILES['upload_file']['name'];
  $size = $_FILES['upload_file']['size'];
  $regdate = date("Y-m-d");
 
  $sql = "insert into webhard (fname, size, regdate)";
  $sql .= "values ('$fname', '$size', '$regdate')";
  $mysqli->query($sql);
 
}
else {
  echo "<script>
  window.alert('업로드 실패!')
  history.go(-1)
  </script>";
}
 
?>
 
cs