-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.php
71 lines (40 loc) · 1.2 KB
/
file.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
session_start();
if( isset($_POST['submit']) ) {
$name = "fname";
$dir="uploads/";
$new_name = false;
$image = $_FILES["image"]["name"];
$tmp_name = $_FILES["image"]["tmp_name"];
if( file_exists("uploads/" .$image) ) {
echo "file already exists";
} elseif( move_uploaded_file ( $tmp_name, "uploads/".$image) ) {
$get_name = date("d-m-y-h-i-sa");
// $oldname = $dir . $image;
//rename($oldname,$get_name);
//echo $getpath = pathinfo($_FILES["image"]["name"],PATHINFO_FILENAME );
$_FILES["image"]["name"] = $get_name;
echo $new_image_name = $_FILES["image"]["name"] . session_id();
echo "<br> file uploaded successfully";
}
$data = ['name'=>$name, "image"=>$new_image_name];
$json_obj = json_encode($data);
//$op_file = fopen($new_name.".json","w");
$filename = date("d-m-y-h-i-sa");
$my_file = fopen($filename.".json", "w") or die("Unable to open file!");
fwrite($my_file, $json_obj);
//fwrite($op_file,$json_obj);
fclose($my_file);
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image" >
<input type="submit" name="submit">
</form>
</body>
</html>