summaryrefslogtreecommitdiff
path: root/lib/file/upload.php
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-06-21 16:34:27 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-06-21 16:34:27 +0200
commit889e8eaf7c40817663dd602a21ac771062ccac3b (patch)
treeca8ac81ee202165333e5ffe16147d09e5cdaf2ab /lib/file/upload.php
parent5c4caed8560d5fded00525844dfa8386b97e7918 (diff)
downloadBits-889e8eaf7c40817663dd602a21ac771062ccac3b.tar.gz
Bits-889e8eaf7c40817663dd602a21ac771062ccac3b.zip
Big change, sir. Can now upload any kind of files.
Diffstat (limited to 'lib/file/upload.php')
-rw-r--r--lib/file/upload.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/file/upload.php b/lib/file/upload.php
new file mode 100644
index 0000000..4b5299d
--- /dev/null
+++ b/lib/file/upload.php
@@ -0,0 +1,54 @@
+<?php
+
+$title = "Upload a file";
+
+require("lib/conf/file.php");
+
+
+if (isset($_FILES['file']) && isset($_POST['name'])) {
+ $name = esca($_POST['name']);
+ if ($name == "") $name = $_FILES['file']['name'];
+ if ($_FILES['file']['error'] != 0) {
+ $error = "Sorry, an error occurred while uploading your file. Try with a smaller one.";
+ require("tpl/file/upload.php");
+ }
+ $origname = strtolower(basename($_FILES['file']['name']));
+ $type = preg_replace("#^.+\.([a-z0-9]+)$#", "$1", $origname);
+
+ sql("INSERT INTO files(owner, extension, name, upl_date) VALUES(" . $user['id'] . ", '$type', '" . escs($name) . "', NOW())");
+ $id = mysql_insert_id();
+ $filen = $savedir . $id . "." . $type;
+ if (!copy($_FILES['file']['tmp_name'], $filen)) {
+ $error = "An internal error occurred. You might want to try again later.";
+ sql("DELETE FROM files WHERE id = $id");
+ require("tpl/file/upload.php");
+ }
+
+ if (has_mini($type)) {
+ $minin = $savedir . $id . "-min." . $type;
+ if ($type == "png")
+ $source = imagecreatefrompng($filen);
+ elseif ($type == "jpg" || $type == "jpeg")
+ $source = imagecreatefromjpeg($filen);
+ elseif ($type == "gif")
+ $source = imagecreatefromgif($filen);
+ $l = imagesx($source);
+ $h = imagesy($source);
+ $l2 = $img_mini_width;
+ $h2 = $l2 * $h / $l;
+ $mini = imagecreatetruecolor($l2, $h2);
+ imagecopyresampled($mini, $source, 0, 0, 0, 0, $l2, $h2, $l, $h);
+ if ($type == "png")
+ imagepng($mini, $minin);
+ elseif ($type == "jpg")
+ imagejpeg($mini, $minin);
+ elseif ($type == "gif")
+ imagegif($mini, $minin);
+ $message = "Your image has been uploaded successfully and a miniature has been created.";
+ } else {
+ $message = "Your file has been uploaded successfully.";
+ }
+ require("tpl/file/upload-ok.php");
+} else {
+ require("tpl/file/upload.php");
+}