-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgupload.php
More file actions
87 lines (66 loc) · 2.28 KB
/
imgupload.php
File metadata and controls
87 lines (66 loc) · 2.28 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
$connect = mysql_connect('localhost', 'root', 'bitnami');
if (!$connect){
echo('cannot connect\n');
}
mysql_select_db("socialnetwork");
session_start();
if (!isset($_SESSION['uid'])) {
header("Location: login.html");
}
$uid = $_SESSION['uid'];
$name = $_SESSION['name'];
$filename = $_FILES["file"]["name"];
$x = $uid . "-" . time();
$allowedExts = array("jpg", "jpeg", "JPG", "JPEG", "Jpg", "Jpeg", "PNG", "Png", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
$location = "imageupload/" . $x . "." . $extension;//$name;
//($_FILES["file"]["type"] == "image/gif")||
if ((($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else {
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
//echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("imageupload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
}
else {
move_uploaded_file($_FILES["file"]["tmp_name"],
$location);//"imageupload/" . $_FILES["file"]["name"]);
}
}
}
else {
echo "Invalid file";
}
$sql = "INSERT INTO `imgurls` (`uid`, `url`)
VALUES ('$uid', '$location')";
mysql_query($sql);
$picture = $location;//$_FILES['file']['name'];
echo("location set<br />");
/*original file location*/
$file = $location;//'imageupload/'.$name;
move_uploaded_file($_FILES["file"]["tmp_name"], $picture);
/*save thumbnail location*/
$save = 'imgthumb/'.$picture;
// Magic Begins Here ......
require "WideImage.php";
$image = WideImage::load($file);
$thumb = $image->resizeDown(200, 40, 'inside');
$thumb->saveToFile($save);
$post = "<a href=\"profile.php?id=" . $uid . "\">" . $name . "</a> uploaded a picture.<br /><img style=\"max-width:100%;\" src=\"" . $location . "\" \>"
$day = date('l');
$time = time();
$sqlb = "INSERT INTO `posts` (`fid`, `post`, `day`, `time`)
VALUES ('$uid', '$post', '$day', '$time')";
mysql_query($sqlb);
echo("done");
header( 'Location: settings.php' ) ;
?>