mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-14 12:08:01 +00:00
added support for POST upload via API
This commit is contained in:
14
README.md
Executable file → Normal file
14
README.md
Executable file → Normal file
@@ -59,7 +59,7 @@ You can also combine as many options as you want. Even multiple times! Want your
|
|||||||
|
|
||||||
## How does the external-upload-API work?
|
## How does the external-upload-API work?
|
||||||
|
|
||||||
### Upload from URL
|
### Upload from external URL
|
||||||
PictShare has a simple REST API to upload remote pictures. The API can be accessed via the backend.php file like this:
|
PictShare has a simple REST API to upload remote pictures. The API can be accessed via the backend.php file like this:
|
||||||
|
|
||||||
```https://pictshare.net/backend.php?getimage=<URL of the image you want to upload>```.
|
```https://pictshare.net/backend.php?getimage=<URL of the image you want to upload>```.
|
||||||
@@ -70,8 +70,18 @@ Request: ```https://pictshare.net/backend.php?getimage=https://www.0xf.at/css/im
|
|||||||
|
|
||||||
The server will answer with the file name and the server path in JSON:
|
The server will answer with the file name and the server path in JSON:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"status":"OK","type":"png","hash":"10ba188162.png","url":"https:\/\/pictshare.net\/10ba188162.png"}
|
||||||
```
|
```
|
||||||
{"status":"OK","type":"png","hash":"10ba188162.png","url":"http:\/\/pictshare.net\/10ba188162.png"}
|
|
||||||
|
### Upload via POST
|
||||||
|
|
||||||
|
Send a POST request to ```https://pictshare.net/backend.php``` and send the image in the variable ```postimage```.
|
||||||
|
|
||||||
|
Server will return JSON of uploaded data like this:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"status":"OK","type":"png","hash":"2f18a052c4.png","url":"https:\/\/pictshare.net\/2f18a052c4.png","domain":"https:\/\/pictshare.net\/"}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Upload from base64 string
|
### Upload from base64 string
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ if($_REQUEST['getimage'])
|
|||||||
|
|
||||||
echo json_encode($pm->uploadImageFromURL($url));
|
echo json_encode($pm->uploadImageFromURL($url));
|
||||||
}
|
}
|
||||||
|
if($_FILES['postimage'])
|
||||||
|
{
|
||||||
|
$image = $_FILES['postimage'];
|
||||||
|
echo json_encode($pm->processSingleUpload($file,'postimage'));
|
||||||
|
}
|
||||||
else if($_REQUEST['base64'])
|
else if($_REQUEST['base64'])
|
||||||
{
|
{
|
||||||
$data = $_REQUEST['base64'];
|
$data = $_REQUEST['base64'];
|
||||||
@@ -37,6 +42,5 @@ else if($_REQUEST['base64'])
|
|||||||
}
|
}
|
||||||
else if($_REQUEST['getsize'])
|
else if($_REQUEST['getsize'])
|
||||||
echo json_encode($pm->getSizeOfURL($_REQUEST['getsize']));
|
echo json_encode($pm->getSizeOfURL($_REQUEST['getsize']));
|
||||||
|
|
||||||
else
|
else
|
||||||
echo json_encode(array('status'=>'ERR'));
|
echo json_encode(array('status'=>'ERR'));
|
||||||
|
|||||||
@@ -316,6 +316,27 @@ class PictshareModel extends Model
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processSingleUpload($file,$name)
|
||||||
|
{
|
||||||
|
if(UPLOAD_CODE!=false && !$pm->uploadCodeExists($_REQUEST['upload_code']))
|
||||||
|
exit(json_encode(array('status'=>'ERR','reason'=>'Wrong upload code provided')));
|
||||||
|
|
||||||
|
$im = new Image();
|
||||||
|
$i = 0;
|
||||||
|
if ($_FILES[$name]["error"] == UPLOAD_ERR_OK)
|
||||||
|
{
|
||||||
|
$data = $this->uploadImageFromURL($_FILES[$name]["tmp_name"]);
|
||||||
|
if($data['status']=='OK')
|
||||||
|
{
|
||||||
|
$hash = $data['hash'];
|
||||||
|
return array('status'=>'OK','type'=>$type,'hash'=>$hash,'url'=>DOMAINPATH.$hash,'domain'=>DOMAINPATH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
function ProcessUploads()
|
function ProcessUploads()
|
||||||
{
|
{
|
||||||
if(UPLOAD_CODE && !$this->uploadCodeExists($_REQUEST['upload_code']))
|
if(UPLOAD_CODE && !$this->uploadCodeExists($_REQUEST['upload_code']))
|
||||||
|
|||||||
Reference in New Issue
Block a user