Last active
December 12, 2015 09:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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