[Tutorial] Your own screenshot server

BoTz

Member
Apr 12, 2016
57
17
43
So, actually this tutorial is about ShareX, you can download it here https://getsharex.com/
If u want to go simple, you can use imgur or a another standard host.
But if you want a own screenshot server, you can use this tutorial.

What you need:
- a webserver (apache2 or something else)
- php
- ShareX
A VPS with Debian is perfectly for this.

Tutorial:
Edit your upload.php and change "yourdomain.com" to your own domain.
Edit yourkey to a password
upload.php
Code:
<?php
$key            = "yourkey";
$redirect       = "http://yourdomain.com/";
$domain         = "yourdomain.com";
$filenamelength = 8;
#Comment this next line if you want Robots to index this site.
if ($_SERVER["REQUEST_URI"] == "/robot.txt") {
    die("User-agent: *\nDisallow: /");
}
#Don't edit below this line inless you know what you are doing...
$urldata = explode("/", $_SERVER["REQUEST_URI"]);

if (isset($_POST['k'])) {
    if ($_POST['k'] != $key) {
        echo ('Error Key wrong.');
        die();
    }
}

function createthumb($name, $filename, $new_w, $new_h)
{
    $system  = explode('.', $name);
    $src_img = imagecreatefromstring(file_get_contents($name));
    $old_x   = imageSX($src_img);
    $old_y   = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    if (preg_match("/png/", $system[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
if (isset($_GET['tn'])) {
    if (!file_exists('tn_' . $_GET['tn'])) {
        createthumb($_GET['tn'], 'tn_' . $_GET['tn'], 100, 100);
    }
    header('Location: http://' . $domain . '/tn_' . $_GET['tn']);
    die();
}

if (isset($_GET['k'])) {
    if ($_GET['k'] == $key) {
        if (isset($_GET['delete'])) {
            if (file_exists($_GET['delete'])) {
                if (isset($_GET['delete'])) {
                    if (file_exists('tn_' . $_GET['delete'])) {
                        unlink('tn_' . $_GET['delete']);
                    }
                    unlink($_GET['delete']);
                    echo "Your uploaded file has been deleted";
                    die();
                } else {
                    echo "Your file you want deleted does not exist";
                }
            }
        }
    }
}
if (isset($_POST['k'])) {
    if ($_POST['k'] == $key) {
        header("Content-Type: application/json");
        if (isset($_GET['up'])) {
            $target = getcwd() . "/" . basename($_FILES['d']['name']);
            if (move_uploaded_file($_FILES['d']['tmp_name'], $target)) {
                $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength) . "." . end(explode(".", $_FILES["d"]["name"]));
                while (file_exists($filename)) {
                    $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength) . "." . end(explode(".", $_FILES["d"]["name"]));
                }
                rename(getcwd() . "/" . basename($_FILES['d']['name']), getcwd() . "/" . $filename);
                echo json_encode(array(
                    'filename' => $filename,
                    'key' => $key
                ));
            } else {
                echo "Sorry, there was a problem uploading your file.";
            }
        }
    } else {
        echo ('404');
    }
} else {
    echo ('Welcome.');
}
?>
.htaccess
Code:
<Files *.php>
    php_flag engine off
    AddType text/plain php
</Files>

<Files index.php>
    Order Allow,Deny
    Allow from all
    php_flag engine on
    RemoveType text/plain php
</Files>

Upload both files to your ftp and give them full rights (777)
Go to ShareX - Destinations - Destination Settings - Scroll down to custom uploaders - Click on add and change everything to this ->[/COLOR]
05DryOvK.png


http://yourdomain.com/upload.php/?up=

\"domain\":\"(.+?)\"
\"key\":\"(.+?)\"
\"filename\":\"(.+?)\"


http://yourdomain.com/$json:filename$
http://yourdomain.com/?tn=$json:filename$
http://yourdomain.com/?k=$json:key$&delete=$json:filename$

Click on Update to save it. (At the left site, not in the middle)
Change your Destination settings to your new uploader
76FEpGTI.png


If you have any questions, let me know.
Credits:

BoTz
radat
 
Last edited by a moderator:

EscuderoKevin

Well-Known Member
Jul 2, 2015
380
181
130
So, actually this tutorial is about ShareX, you can download it here https://getsharex.com/
If u want to go simple, you can use imgur or a another standard hosts.
But if you want a own screenshot server, you can use this tutorial.

What you need:
- a webserver (apache2 or something else)
- php
- ShareX
A VPS with Debian is perfectly for this.

Tutorial:
Edit your upload.php and change "yourdomain.com" to your own domain.
Edit yourkey to a password
upload.php
Code:
<?php
$key            = "yourkey";
$redirect       = "http://yourdomain.com/";
$domain         = "yourdomain.com";
$filenamelength = 8;
#Comment this next line if you want Robots to index this site.
if ($_SERVER["REQUEST_URI"] == "/robot.txt") {
    die("User-agent: *\nDisallow: /");
}
#Don't edit below this line inless you know what you are doing...
$urldata = explode("/", $_SERVER["REQUEST_URI"]);

if (isset($_POST['k'])) {
    if ($_POST['k'] != $key) {
        echo ('Error Key wrong.');
        die();
    }
}

function createthumb($name, $filename, $new_w, $new_h)
{
    $system  = explode('.', $name);
    $src_img = imagecreatefromstring(file_get_contents($name));
    $old_x   = imageSX($src_img);
    $old_y   = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    if (preg_match("/png/", $system[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
if (isset($_GET['tn'])) {
    if (!file_exists('tn_' . $_GET['tn'])) {
        createthumb($_GET['tn'], 'tn_' . $_GET['tn'], 100, 100);
    }
    header('Location: http://' . $domain . '/tn_' . $_GET['tn']);
    die();
}

if (isset($_GET['k'])) {
    if ($_GET['k'] == $key) {
        if (isset($_GET['delete'])) {
            if (file_exists($_GET['delete'])) {
                if (isset($_GET['delete'])) {
                    if (file_exists('tn_' . $_GET['delete'])) {
                        unlink('tn_' . $_GET['delete']);
                    }
                    unlink($_GET['delete']);
                    echo "Your uploaded file has been deleted";
                    die();
                } else {
                    echo "Your file you want deleted does not exist";
                }
            }
        }
    }
}
if (isset($_POST['k'])) {
    if ($_POST['k'] == $key) {
        header("Content-Type: application/json");
        if (isset($_GET['up'])) {
            $target = getcwd() . "/" . basename($_FILES['d']['name']);
            if (move_uploaded_file($_FILES['d']['tmp_name'], $target)) {
                $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength) . "." . end(explode(".", $_FILES["d"]["name"]));
                while (file_exists($filename)) {
                    $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength) . "." . end(explode(".", $_FILES["d"]["name"]));
                }
                rename(getcwd() . "/" . basename($_FILES['d']['name']), getcwd() . "/" . $filename);
                echo json_encode(array(
                    'filename' => $filename,
                    'key' => $key
                ));
            } else {
                echo "Sorry, there was a problem uploading your file.";
            }
        }
    } else {
        echo ('404');
    }
} else {
    echo ('Welcome.');
}
?>

.htaccess
Code:
<Files *.php>
    php_flag engine off
    AddType text/plain php
</Files>

<Files index.php>
    Order Allow,Deny
    Allow from all
    php_flag engine on
    RemoveType text/plain php
</Files>

Upload both files to your ftp and give them full rights (777)
Go to ShareX - Destinations - Destination Settings - Scroll down to custom uploaders - Click on add and change everything to this ->

05DryOvK.png


http://yourdomain.com/upload.php/?up=

\"domain\":\"(.+?)\"
\"key\":\"(.+?)\"
\"filename\":\"(.+?)\"


http://yourdomain.com/$json:filename$
http://yourdomain.com/?tn=$json:filename$
http://yourdomain.com/?k=$json:key$&delete=$json:filename$

Click on Update to save it. (At the left site, not in the middle)
Change your Destination settings to your new uploader
76FEpGTI.png


If you have any questions, let me know.

Credits:


BoTz
radat


Its for backup server ? , you can use zip + dropbox uploader
 

Ch4ch4rR4t0

Active Member
Aug 19, 2016
77
7
83
Thanks bro :D
more i have error!

Code:
Error: Failed.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   in Newtonsoft.Json.JsonTextReader.ParseValue()
   in Newtonsoft.Json.JsonTextReader.Read()
    in Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
    in Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
    in ShareX.HelpersLib.Helpers.ParseJSON(String text, String jsonPath)
    in ShareX.UploadersLib.CustomUploaderItem.ParseURL(String url)
    in ShareX.UploadersLib.CustomUploaderItem.ParseResponse(UploadResult result, Boolean isShortenedURL)
    in ShareX.UploadersLib.ImageUploaders.CustomImageUploader.Upload(Stream stream, String fileName)
 

PAY-BACK

Member
Aug 20, 2015
20
6
35
StackTrace:
When System.Net.HttpWebRequest.GetRequestStream (TransportContext & context)
When System.Net.HttpWebRequest.GetRequestStream ()
When ShareX.UploadersLib.Uploader.UploadData (Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String contentType, String metadata)
1438-03-17 01: 22: 19.218 - Task failed. Filename: chrome_2016-12-16_01-22-17.png, Errors:
Message:
Unable to run the name resolution: 'picture.sauuu.us.us'

StackTrace:
When System.Net.HttpWebRequest.GetRequestStream (TransportContext & context)
When System.Net.HttpWebRequest.GetRequestStream ()
When ShareX.UploadersLib.Uploader.UploadData (Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String contentType, String metadata)
1438-03-17 01: 22: 19.326 - UploadersConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ UploadersConfig.json
1438-03-17 01: 22: 19.326 - UploadersConfig save started: C: \ Users \ **** \ Documents \ ShareX \ UploadersConfig.json
1438-03-17 01: 22: 19.326 - ApplicationConfig save started: C: \ Users \ **** \ Documents \ ShareX \ ApplicationConfig.json
1438-03-17 01: 22: 19.326 - HotkeysConfig save started: C: \ Users \ **** \ Documents \ ShareX \ HotkeysConfig.json
1438-03-17 01: 22: 19.338 - HotkeysConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ HotkeysConfig.json
1438-03-17 01: 22: 19.365 - ApplicationConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ ApplicationConfig.json
1438-03-17 01: 22: 25.590 - Executing: Open main window
^
Help please ?
 

Kleberstoff

Knowledge Seeker
VIP
Dec 29, 2015
308
214
158
StackTrace:
When System.Net.HttpWebRequest.GetRequestStream (TransportContext & context)
When System.Net.HttpWebRequest.GetRequestStream ()
When ShareX.UploadersLib.Uploader.UploadData (Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String contentType, String metadata)
1438-03-17 01: 22: 19.218 - Task failed. Filename: chrome_2016-12-16_01-22-17.png, Errors:
Message:
Unable to run the name resolution: 'picture.sauuu.us.us'

StackTrace:
When System.Net.HttpWebRequest.GetRequestStream (TransportContext & context)
When System.Net.HttpWebRequest.GetRequestStream ()
When ShareX.UploadersLib.Uploader.UploadData (Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String contentType, String metadata)
1438-03-17 01: 22: 19.326 - UploadersConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ UploadersConfig.json
1438-03-17 01: 22: 19.326 - UploadersConfig save started: C: \ Users \ **** \ Documents \ ShareX \ UploadersConfig.json
1438-03-17 01: 22: 19.326 - ApplicationConfig save started: C: \ Users \ **** \ Documents \ ShareX \ ApplicationConfig.json
1438-03-17 01: 22: 19.326 - HotkeysConfig save started: C: \ Users \ **** \ Documents \ ShareX \ HotkeysConfig.json
1438-03-17 01: 22: 19.338 - HotkeysConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ HotkeysConfig.json
1438-03-17 01: 22: 19.365 - ApplicationConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ ApplicationConfig.json
1438-03-17 01: 22: 25.590 - Executing: Open main window
^
Help please ?
picture.sauuu.us.us should be picture.sauuu.us
Also, please use spoilers or code to make it more readable
 

PAY-BACK

Member
Aug 20, 2015
20
6
35
picture.sauuu.us.us should be picture.sauuu.us
Also, please use spoilers or code to make it more readable
Error: Response parse failed.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
in Newtonsoft.Json.JsonTextReader.ParseValue()
in Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
in Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
in ShareX.HelpersLib.Helpers.ParseJSON(String text, String jsonPath)
in ShareX.UploadersLib.CustomUploaderItem.ParseURL(String url)
in ShareX.UploadersLib.CustomUploaderItem.ParseResponse(UploadResult result, Boolean isShortenedURL)
in ShareX.UploadersLib.ImageUploaders.CustomImageUploader.Upload(Stream stream, String fileName)
 

Kleberstoff

Knowledge Seeker
VIP
Dec 29, 2015
308
214
158
Error: Response parse failed.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
in Newtonsoft.Json.JsonTextReader.ParseValue()
in Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
in Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
in ShareX.HelpersLib.Helpers.ParseJSON(String text, String jsonPath)
in ShareX.UploadersLib.CustomUploaderItem.ParseURL(String url)
in ShareX.UploadersLib.CustomUploaderItem.ParseResponse(UploadResult result, Boolean isShortenedURL)
in ShareX.UploadersLib.ImageUploaders.CustomImageUploader.Upload(Stream stream, String fileName)

Double Check your Settings and the upload.php needs write Permissions.
Code:
chmod u+w upload.php
should do it.
 
Top