Example #1
0
/**
 * @param    $object_id      Name to assign
 * @param    $content_bytes  Content of file
 * @param    $mime_type      MIME/Type to assign
 * @return   mixed   URL of uploaded file on success, false or PEAR_Error on failure.
 */
function post_file($object_id, $content_bytes, $mime_type)
{
    return AWS_ACCESS_KEY && AWS_SECRET_KEY && S3_BUCKET_ID ? post_file_s3($object_id, $content_bytes, $mime_type) : post_file_local($object_id, $content_bytes);
}
Example #2
0
$redirect = preg_match('#^http://#', $_POST['redirect']) ? $_POST['redirect'] : null;
$expiration = $_POST['expiration'] ? $_POST['expiration'] : null;
$file = is_array($_FILES['file']) ? $_FILES['file'] : null;
if (strtotime($expiration) < time()) {
    die_with_code(401, "Sorry, expiration date {$expiration} has come and gone - " . date('r', strtotime($expiration)));
}
if ($file['error'] > 0) {
    die_with_code(400, "Sorry, encountered error #{$file['error']} (see http://us.php.net/manual/en/features.file-upload.errors.php)");
}
$posted_signature = $_POST['signature'] ? $_POST['signature'] : null;
$expected_signature = sign_post_details($dirname, $expiration, API_PASSWORD);
if ($posted_signature != $expected_signature) {
    die_with_code(401, 'Sorry, bad signature');
}
if (is_array($file) && is_uploaded_file($file['tmp_name'])) {
    $object_id = rtrim($dirname, '/') . '/' . ltrim($file['name'], '/');
    $content_bytes = file_get_contents($file['tmp_name']);
    $url = post_file_local($object_id, $content_bytes);
}
if ($redirect) {
    $redirect = new Net_URL($redirect);
    $redirect->addQueryString('url', $url);
    $redirect = $redirect->getURL();
}
if ($redirect) {
    header("Location: {$redirect}");
}
header('Content-Type: text/plain');
echo "Thanks, I think I handled your file, so thanks.\n";
echo "That's: {$file['name']}\n";
echo "Or? {$file['error']}\n";