<!--
# Dropbox-Upload-Script, v6
# Initial version from: http://www.ampercent.com/dropbox-uploader-allow-users-upload-files-dropbox-account/
# And taken from: http://jaka.kubje.org/projects/dropbox-uploader/example/
# Graphics from: http://www.addictivetips.com/internet-tips/allow-anyone-to-upload-files-to-your-dropbox-folder/
# Modified by kingofcomedy, 2010-08/09
# http://dropbox.kingofcomedy.de
//-->
<?php
$passw = "default"; //change this to a password of your choice.
$only_some_extensions_are_allowed = 1; // set to 0 if you want to allow every extension
$filesize_limit = "100"; // max. filesize in kybte
// enter dropbox credentials below
$data = array(
"email" => "dx@freenet.de",
"password" => "xxx",
"directories" => array(
# real-folder => a name which will be shown in the dropdown
"shared" => "kunde",
"shared/test" => "my test folder inside my shared folder"
)
);
// which file-extensions are allowed for an upload
$ext_upload = array(
"exe",
"zip",
"pdf",
"rar",
"7z"
);
// which file-extensions are allowed for a link
$ext_link = array(
"exe",
"zip",
"gz",
"jpg"
);
function CleanArray($OldArray){
$i = 0;
$NewArray = array();
foreach($OldArray as $value){
if($value != "" && strpos($value, "Copy a link into this field!") === false){
$NewArray[$i] = $value;
$i++;
}
}
return $NewArray;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dropbox Uploader v0.6</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script language="javascript" type="text/javascript">
<!--
function show(what){
if(what == "link"){
document.getElementById("file").style.display = "none";
document.getElementById("link").style.display = "";
}else if(what == "file"){
document.getElementById("link").style.display = "none";
document.getElementById("file").style.display = "";
}
}
//-->
</script>
</head>
<body>
<?php
if ($_POST) {
require 'DropboxUploader.php';
try {
$keys = array_keys($data["directories"]);
$directory = $keys[$_POST["folder"]];
if ($_POST['txtPassword'] != $passw)
throw new Exception('Wrong Password');
$tmpDir = uniqid('/tmp/DropboxUploader-');
if (!mkdir($tmpDir))
throw new Exception('Cannot create temporary directory!');
$_LINK = CleanArray($_POST["link"]);
if($_POST["choice"] == "file"){
for($c=0; $c<4; $c++){
if($_FILES["file"]['name'][$c] != ''){
$filename = $_FILES["file"]['name'][$c];
$info = pathinfo($filename);
$ext = $info['extension'];
if(!in_array($ext,$ext_upload) && $only_some_extensions_are_allowed == 1)
throw new Exception('This file-extension (*.'.$ext.') is not allowed.');
// Rename uploaded file to reflect original name
if ($_FILES["file"]['error'][$c] !== UPLOAD_ERR_OK)
throw new Exception('File was not successfully uploaded from your computer.');
if ($_FILES["file"]['name'][$c] === "")
throw new Exception('File name not supplied by the browser.');
$tmpFile = $tmpDir.'/'.str_replace("/\0", '_', $_FILES["file"]['name'][$c]);
if (!move_uploaded_file($_FILES["file"]['tmp_name'][$c], $tmpFile))
throw new Exception('Cannot rename uploaded file!');
$tmpFilesize = filesize($tmpFile);
if($tmpFilesize > ($filesize_limit*1024)){
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
throw new Exception('File ('.$_FILES["file"]['name'][$c].') too big! ('.$tmpFilesize.' > '.($filesize_limit*1024).')');
}
$uploader = new DropboxUploader($data["email"], $data["password"]);
$uploader->upload($tmpFile, $directory);
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
}
}
}elseif($_POST["choice"] == "link"){
for($c=0; $c<count($_LINK); $c++){
$filename = $_LINK[$c];
$info = pathinfo($filename);
$ext = $info['extension'];
if(!in_array($ext,$ext_link) && $only_some_extensions_are_allowed == 1)
throw new Exception('This file-extension is not allowed.');
copy($filename, $tmpDir ."/". end(explode("/", $filename)));
$tmpFile = $tmpDir.'/'.str_replace("/\0", '_', end(explode("/", $filename)));
$tmpFilesize = filesize($tmpFile);
if($tmpFilesize > ($filesize_limit*1024)){
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
throw new Exception('File ('.$filename.') too big! ('.$tmpFilesize.' > '.($filesize_limit*1024).')');
}
$uploader = new DropboxUploader($data["email"], $data["password"]);
$uploader->upload($tmpFile, $directory);
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
}
}
$error = '<span style="color:#00ff00; font-weight:bold;">File(s) successfully uploaded to your dropbox ('.$directory.')!</span>';
} catch(Exception $e) {
$error = '<span style="color:#ff0000; font-weight:bold;">Error: ' . htmlspecialchars($e->getMessage()) . '</span>';
}
if (isset($tmpDir) && file_exists($tmpDir))
rmdir($tmpDir);
}
# echo ini_get('post_max_size');
# echo ini_get('upload_max_filesize');
?>
<div class="blue-box">
<div style="height:384px;">
<div style="padding-top:40px; text-align:center;">
<h1>Dropbox Uploader</h1>
<form action="index.php" method="post" enctype="multipart/form-data" style="display:inline;">
<strong>Source:</strong> <input type="radio" name="choice" value="file" onclick="javascript:show('file');" checked />file or
<input type="radio" name="choice" value="link" onclick="javascript:show('link');" />link
<br /><br />
<div style="width:650px; height:140px; margin:auto;">
<div style="float:left;">
<div id="file">
<input type="file" name="file[]" /><br />
<input type="file" name="file[]" /><br />
<input type="file" name="file[]" /><br />
<input type="file" name="file[]" /><br /><br />
<?php
if($only_some_extensions_are_allowed == 1) echo "<strong>Allowed extensions:</strong> " . implode(", ", $ext_upload) . "<br /><br />";
?>
</div>
<div id="link" style="display:none;">
<input type="text" name="link[]" size="40" value="Copy a link into this field!" onfocus='this.value = "";' /><br />
<input type="text" name="link[]" size="40" value="Copy a link into this field!" onfocus='this.value = "";' /><br />
<input type="text" name="link[]" size="40" value="Copy a link into this field!" onfocus='this.value = "";' /><br />
<input type="text" name="link[]" size="40" value="Copy a link into this field!" onfocus='this.value = "";' /><br /><br />
<?php
if($only_some_extensions_are_allowed == 1) echo "<strong>Allowed extensions:</strong> " . implode(", ", $ext_link) . "<br /><br />";
?>
</div>
</div>
<div style="float:right; padding-left:20px; text-align:left;">
<strong>Destination:</strong> <select name="folder">
<?php
$i = 0;
foreach($data["directories"] AS $output){
echo '<option value="'.$i.'">'.$output.'</option>';
$i++;
}
?>
</select>
<br /><br />
<strong>Password:</strong> <input type="password" title="Enter your password" name="txtPassword" />
<br /><br />
</div>
<div style="clear:both;"></div>
</div>
<input type="submit" value="Upload the file to my Dropbox!" />
</form>
<br /><br />
<?php if(isset($error)) echo $error; ?>
</div>
</div>
</div>
</body>
</html>