Skip to content

Instantly share code, notes, and snippets.

@since1976
Created August 23, 2011 01:46
Show Gist options
  • Save since1976/1164115 to your computer and use it in GitHub Desktop.
Save since1976/1164115 to your computer and use it in GitHub Desktop.
Custom EE Dropbox upload form
<?php
if ($_POST) {
require CUSTOM_SCRIPTS_FOLDER.'dropboxuploader.php';
try {
// Rename uploaded file to reflect original name
if ($_FILES['file']['error'] !== UPLOAD_ERR_OK)
throw new Exception('File was not successfully uploaded from your computer.');
$tmpDir = uniqid('/tmp/DropboxUploader-');
if (!mkdir($tmpDir))
throw new Exception('Cannot create temporary directory!');
if ($_FILES['file']['name'] === "")
throw new Exception('File name not supplied by the browser.');
$tmpFile = $tmpDir.'/'.str_replace("/\0", '_', $_FILES['file']['name']);
if (!move_uploaded_file($_FILES['file']['tmp_name'], $tmpFile))
throw new Exception('Cannot rename uploaded file!');
// Upload
$uploader = new DropboxUploader('[email protected]', 'password');
$uploader->upload($tmpFile, 'client_files/'.$_POST['dest']);
$this->EE->load->library('email');
// $this->EE->email->initialize($config);
$this->EE->email->from($this->EE->input->post('email'), $this->EE->input->post('name'));
$this->EE->email->to('[email protected]');
//$this->EE->email->cc('[email protected]');
//$this->EE->email->bcc('[email protected]');
$filename = $_FILES['file']['name'];
//echo var_dump($_FILES['file']['name']);
$this->EE->email->subject('File uploaded to your Dropbox');
$this->EE->email->message('A new file has been uploaded to your Dropbox.'."\n\n".
'Filename: '.
$filename . "\n\n" .
'Destination: '.
$this->EE->input->post('dest') . "\n\n" .
'Additional Instructions: '.
$this->EE->input->post('notes') . "\n\n"
);
$this->EE->email->send();
$this->EE->functions->redirect('/success');
//echo $this->EE->email->print_debugger();
echo '<span style="color: green">Thanks your file has successfully been uploaded to our server!</span>';
} catch(Exception $e) {
echo '<span style="color: red">Error: ' . htmlspecialchars($e->getMessage()) . '</span>';
}
// Clean up
if (isset($tmpFile) && file_exists($tmpFile))
unlink($tmpFile);
if (isset($tmpDir) && file_exists($tmpDir))
rmdir($tmpDir);
}
?>
<form method="post" enctype="multipart/form-data">
<div class="form-field"><label>Destination directory (optional)</label><input type="text" name="dest" /> <p class="field-notes">e.g. "company name/project", will be created if it doesn't exist</p></div>
<div class="form-field"><label>File</label><input type="file" name="file" /></div>
<div class="form-field"><label>Your name</label> <input type="text" name="name" /></div>
<div class="form-field"><label>Your email address</label> <input type="email" name="email" /></div>
<div class="form-field"><label>Additional notes:</label><textarea name="notes"></textarea></div>
<div><input type="submit" name="submit" value="Upload file now" /></div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment