Skip to content

Instantly share code, notes, and snippets.

@sebietter
Last active December 12, 2015 09:09
Show Gist options
  • Save sebietter/4749689 to your computer and use it in GitHub Desktop.
Save sebietter/4749689 to your computer and use it in GitHub Desktop.
With this little PHP script you can directly post photos to your server using Tweetbot.
<?php
$saveDir = ""; // place where the images should be saved.
$domain = "THE DOMAIN YOU'RE USING"; // your domain.
//server-side directory
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . $saveDir;
// Image filetype check source:
// http://designshack.net/articles/php-articles/smart-file-type-detection-using-php/
$tempFile = $_FILES['media']['tmp_name'];
$imginfo_array = getimagesize($tempFile);
if ($imginfo_array !== false) {
$mime_type = $imginfo_array['mime'];
$mime_array = array("video/quicktime", "image/png", "image/jpeg", "image/gif", "image/bmp");
if (in_array($mime_type , $mime_array)) {
//generate random filename
while(file_exists($uploadFilename = $uploadsDirectory.time().'-'.$_FILES['media']['name'])){$now++;}
//upload the file to the webserver
@move_uploaded_file($_FILES['media']['tmp_name'], $uploadFilename);
//generate the filename that will be given to Tweetbot
$outputFilename = $domain . $saveDir . basename($uploadFilename);
//respond with JSON encoded media URL
$response = array(url=>$outputFilename);
echo json_encode($response);
}
}
else {
echo "This is not a valid image file";
}
?>
With this little PHP script you can directly post photos to your server using Tweetbot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment