From 6ad94f2063bea75f71931d54cb05c58c00c40a7a Mon Sep 17 00:00:00 2001 From: Christian Haschek Date: Wed, 4 May 2022 22:46:59 +0200 Subject: [PATCH] added php function for uploading --- rtfm/INTEGRATIONS.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/rtfm/INTEGRATIONS.md b/rtfm/INTEGRATIONS.md index a88dc15..e8c4640 100644 --- a/rtfm/INTEGRATIONS.md +++ b/rtfm/INTEGRATIONS.md @@ -43,4 +43,36 @@ result=$(curl -s -F "file=@${1}" https://pictshare.net/api/upload.php | jq -r .u xclip -selection clipboard -t image/png -i $1 google-chrome $result -``` \ No newline at end of file +``` + +# PHP + +```php +/* +* @param $path string Path to the file that should be uploaded +* @param $hash string Optional. File name we want on pictshare for the file +*/ +function pictshareUploadImage($path,$hash=false) +{ + if(!file_exists($path)) return false; + $request = curl_init('https://pictshare.net/api/upload.php'); + + curl_setopt($request, CURLOPT_POST, true); + curl_setopt( + $request, + CURLOPT_POSTFIELDS, + array( + 'file' => curl_file_create($path), + 'hash'=>$hash + )); + + // output the response + curl_setopt($request, CURLOPT_RETURNTRANSFER, true); + $json = json_decode(curl_exec($request).PHP_EOL,true); + + // close the session + curl_close($request); + + return $json; +} +```