Skip to content

Commit 66f4135

Browse files
committed
first commit
1 parent 0a9e0fa commit 66f4135

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

css.css

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#upload {
2+
margin-left: auto;
3+
margin-right: auto;
4+
width: 50%;
5+
}
6+
#info {
7+
font-size: 75%;
8+
}
9+
#image {
10+
margin-left: auto;
11+
margin-right: auto;
12+
width: 50%;
13+
}
14+
#image input[type="text"] {
15+
width: 100%;
16+
}
17+
#image img {
18+
margin-left: auto;
19+
margin-right: auto;
20+
display: block;
21+
max-width: 100%;
22+
max-height: 80%;
23+
}
24+

index.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
// Configuration
3+
$title = 'Image Uploader';
4+
$filedir = 'up';
5+
$maxsize = 5242880; //max size in bytes
6+
$allowedExts = array('png', 'jpg', 'jpeg', 'gif');
7+
$allowedMime = array('image/png', 'image/jpeg', 'image/pjpeg', 'image/gif');
8+
$baseurl = $_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI']).'/'.$filedir;
9+
?>
10+
<html>
11+
<head>
12+
<title><?php print $title; ?></title>
13+
<link rel="stylesheet" href="css.css" type="text/css" />
14+
</head>
15+
<body>
16+
<div id="upload">
17+
<form enctype="multipart/form-data" action="<?php print $_SERVER['PHP_SELF']; ?>" method="POST">
18+
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
19+
Choose a file to upload: <br />
20+
<input size="62" name="file" type="file" accept="image/*" />
21+
<input type="submit" value="Upload File" />
22+
</form>
23+
<div id="info">
24+
Max file size: 5mb <br/>
25+
Supported formats: png, jpg, gif <br/>
26+
Please don't upload anything illegal
27+
</div>
28+
</div>
29+
<div id="image">
30+
<a name="image">
31+
<?php
32+
if($_SERVER['REQUEST_METHOD'] == 'POST') {
33+
$ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
34+
35+
if ((in_array($_FILES['file']['type'], $allowedMime))
36+
&& (in_array(strtolower($ext), $allowedExts))
37+
&& (@getimagesize($_FILES['file']['tmp_name']) !== false)
38+
&& ($_FILES['file']['size'] <= $maxsize)) {
39+
$md5 = substr(md5_file($_FILES['file']['tmp_name']), 0, 7);
40+
$newname = time().$md5.'.'.$ext;
41+
move_uploaded_file($_FILES['file']['tmp_name'], $filedir.'/'.$newname);
42+
$baseurl = $_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI']).'/'.$filedir;
43+
$imgurl = 'http://'.$baseurl.'/'.$newname;
44+
print '<br />';
45+
print 'Your URL:<br />';
46+
print '<input type="text" value="'.$imgurl.'" ><br /><br />';
47+
print '<a href="'.$imgurl.'"><img src="'.$imgurl.'" /></a><br />';
48+
}
49+
50+
else {
51+
print '<br />';
52+
print 'Something went wrong <br />';
53+
}
54+
55+
}
56+
?>
57+
</div>
58+
</body>
59+
</html>
60+

0 commit comments

Comments
 (0)