Using vgy.me on your website is easy. You just need to make a POST
method request to https://vgy.me/upload
. The uploader will always return a JSON response, so you can easily use it with jQuery-based File Uploaders, such as blueimp's jQuery File Uploader, like the basic example below:
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>My File Uploader</title> </head> <body> <input id="fileupload" type="file" name="file[]" multiple> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/blueimp-file-upload/9.19.2/js/vendor/jquery.ui.widget.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/blueimp-file-upload/9.19.2/js/jquery.iframe-transport.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/blueimp-file-upload/9.19.2/js/jquery.fileupload.min.js"></script> <script> $(function() { $("#fileupload").fileupload({ url: "https://vgy.me/upload", dataType: "json", done: function(e, data) { // For single-file upload if(typeof data.result.url != "undefined") { // outputs <p>https://vgy.me/u/abc123</p> $("<p/>").text(data.result.url).appendTo(document.body); } else { // If 2 or more files are uploaded at once $.each(data.result.upload_list, function(index, url) { // outputs <p>https://vgy.me/u/abc123</p> $("<p/>").text(url).appendTo(document.body); }); } } }); }); </script> </body> </html>
For single-file uploads, it will return basic information for that upload, like below:
{ "error": false, "filesize": 123456, "filename": "abc123", "ext": "png", "url": "https://vgy.me/u/abc123", "image": "https://i.vgy.me/abc123.png", "delete": "https://vgy.me/delete/DemoDeleteURL", }
For multi-file uploads, the uploader will always create a random album to store the multiple uploads in. The results will be a single URL to the album, as well as a list of all the uploads within that album:
{
"error": false,
"url": "https://vgy.me/album/DemoAlbum",
"upload_list": {
"https://i.vgy.me/DemoUpload1.png",
"https://i.vgy.me/DemoUpload2.png",
"https://i.vgy.me/DemoUpload3.png",
...
},
}
You can also upload files to our servers through native PHP. Below is an example using PHP 7.0 and cURL:
<?php $ch = curl_init('https://vgy.me/upload'); $file = new CURLFile('/path/to/your/image.jpg', 'mimetype', 'filename'); $data = array('file' => $file); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); echo curl_exec($ch); ?>
Optionally, you can also define a title and description to your upload, simply by appending title
and/or description
as keys to your $data
array with the values as your desired inputs, like the example below:
<?php $ch = curl_init('https://vgy.me/upload'); $file = new CURLFile('/path/to/your/image.jpg', 'mimetype', 'filename'); $data = array('file' => $file, 'title' => 'Beautiful Flowers', 'description' => 'A beautiful photo of flowers at the local park.'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); echo curl_exec($ch); ?>
If you have an account with us, you can generate a userkey (go here) to have your uploader on your website upload files into your account. All you have to do is include "userkey" => "YourUserKey"
into the $data
array as shown in the PHP/cURL example below.
<?php $ch = curl_init("https://vgy.me/upload"); $file = new CURLFile("/path/to/your/image.jpg", "mimetype", "filename"); $data = array("file" => $file, "userkey" => "YourUserKey"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); echo curl_exec($ch); ?>