-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathprocess-multi-upload.php
64 lines (50 loc) · 2.34 KB
/
process-multi-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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
include_once("config.php");
include_once("function-library.php");
?>
<?php
function log_data($data) {
$ourFileName = "logs/".date("Y-m-d").".txt";
$ourFileHandle = fopen($ourFileName, 'a') or die("can't open file");
fwrite($ourFileHandle, date("d/m/Y H:i:s").": ".$data."\n");
fclose($ourFileHandle);
}
log_data("Started import of ".$_FILES['Filedata']['name']);
$userip = $_SERVER['REMOTE_ADDR'];
log_data("User IP is ".$userip);
// validation bits
$filesize = $_FILES['Filedata']['size'];
$tmpfile = $_FILES['Filedata']['tmp_name'];
$filename = $_FILES['Filedata']['name'];
$contenttype = $_FILES['Filedata']['type'];
$extension = pathinfo($_FILES['Filedata']['name']);
$extension = strtolower($extension[extension]);
$valid_ext_types = array('jpeg', 'jpg', 'gif', 'png');
if(!in_array($extension, $valid_ext_types)) {
$error .= "File type does not appear to be a supported image (".$extension."). Please try another format.<br>";
}
if(strlen($error) == 0) {
$uploaddir = 'storage/originals/';
$newfilename = randomfilename() . "." . $extension;
$uploadfile = $uploaddir . $newfilename;
if (!move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadfile)) {
$error .= "Could not move file into storage, please try again later.";
log_data("ERROR: ".$error);
}
else {
// add to db
$userip = $_SERVER['REMOTE_ADDR'];
list($originalwidth, $originalheight, $type, $attr) = getimagesize($uploadfile);
$tracker = randomfilename();
$insert_image = "INSERT INTO images (dateadded, mimetype, originalfilename, filename, filesize, description, originalip, originalwidth, originalheight, lastaccessed, tracker, mutracker) VALUES (NOW(), '".preparedata($contenttype)."', '".preparedata($filename)."', '".preparedata($newfilename)."', '".preparedata($filesize)."', '', '".preparedata($userip)."', '".$originalwidth."', '".$originalheight."', NOW(), '".preparedata($tracker)."', '".preparedata($mutracker)."')";
$do_insert_image = @mysql_query($insert_image);
$item_id = mysql_insert_id();
if($do_insert_image) {
log_data("SUCCESS: Image successfully uploaded. Ref: ".$item_id);
}
else log_data("ERROR: SQL INSERT FAILED - ".$insert_image);
}
}
else log_data("ERROR: ".$error);
log_data("Finished import process for ".$_FILES['Filedata']['name']."\n\r");
?>