MyBB Community Forums

Full Version: Imgur upload for 1.6
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello friends,

I have been trying to get this to work but with no luck

http://community.mybb.com/thread-134658.html

My forum link is www.indiachatforum.net and has Mybb 1.6

I was able to make the changes mentioned in the thread but when I click on the button and select the image I am getting

[img]undefined[/img]

Here is the imgur.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Upload to Imgur</title>
</head>
<body>
<div>
<img src="images/imgur.png" border="0" /></div>

<button onclick="document.querySelector('input').click()">Select file...</button>
<input style="visibility: collapse; width: 0px;" type="file" onchange="upload(this.files[0])">

<script>
    window.ondragover = function(e) {e.preventDefault()}
    window.ondrop = function(e) {e.preventDefault(); upload(e.dataTransfer.files[0]); }
    function upload(file) {

        /* Is the file an image? */
        if (!file || !file.type.match(/image.*/)) return;

        /* It is! */
        document.body.className = "uploading";

        /* Lets build a FormData object*/
        var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
        fd.append("image", file); // Append the file
        var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
        xhr.open("POST", "https://api.imgur.com/3/image.json"); // Boooom!
        xhr.onload = function() {
            var code = '[img]' + JSON.parse(xhr.responseText).data.link + '[/img]';
            var editor = eval('opener.' + 'clickableEditor');
            editor.performInsert(code);
            javascript:window.close()
        }
        // Ok, I don't handle the errors. An exercice for the reader.
        xhr.setRequestHeader('Authorization', 'Client-ID 15-digit-client-id');
        /* And now, we send the formdata */
        xhr.send(fd);
    }
</script>

<span style="color:#fff;text-align:center;display:block;margin: 1em">Browse for your image, or drag and drop it into this window if you use FF or Chrome.</span>

<style>
    body {text-align: center; background-color: #000; overflow-x:hidden; overflow-y:auto; color:#888}
    div { background-color: rgb(43, 43, 43); border-bottom: 4px solid rgb(68, 68, 66); margin: -8px;}
    p {display: none}
    .uploading p {display: inline}
</style>

<p><img src="images/loader.gif" border="0" /></p> 
</body>
</html> 

Has anyone who got this error message was able to get this working?

Please help