-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
41 lines (25 loc) · 977 Bytes
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = 'uploads'; //2
if (!empty($_FILES)) {
$pieces = explode(".", $_FILES['file']['name']);
$_FILES['file']['name'] = uniqid().".".$pieces[count($pieces)-1];
$fileName = $_FILES['file']['name'];
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
$con=mysqli_connect("db.cbn7hdryrize.us-west-2.rds.amazonaws.com","wuichen01","wuichen01","bb");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO pictures (pic_name,description)
VALUES ('$fileName','')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
}
?>