YaBB image upload script

(c) 2003 by Jean-Sbastien Guay
jean_seb@videotron.ca -- http://whitestar02.webhop.org/
--------------------------------------------------------

The files in this archive make up a simple image upload facility (which I will
call "the script" from now on) that I built so that users of my board could post
images without needing to know how to upload the image to some personal web
space or even without having to have any personal web space at all.

If you follow the installation instructions below, the upload script will
replace the "insert image" button on the Post page. That means that users will
no longer be able to post an image without uploading it through the script
first. If this is not what you want, it would probably not be hard to create a
new button beside the "insert image" button instead of replacing it, but I
cannot tell you how to do it.

The script works as follows :
1- The user clicks the "insert image" button. A pop-up window appears.
2- The user can browse to their image, and then clicks the "upload" button.
3- The pop-up closes, and the message field now contains one of two things :
   a) the complete [img] tag for the image.
   b) an error message.

The script will give an error in a few cases :
1- If there is not enough space on the destination drive to save the image, or
   if the web server user does not have the permissions required to save there.
2- If the file was larger than 200 KB (can be changed easily in the script), to
   prevent DOS attacks.
3- If the file was not a gif/jpeg/png image (detected by mime type, more types
   can be added if you want, but I just put the basic web-visible image types).
   Of course, it can be generalized to upload any file, but there are already
   mods to upload files

The script will save the uploaded image on the web server, so be sure you have
enough space free to support that, and try to predict what kind of usage it
will get for your site. One big problem is that I didn't put a check or hard
limit to the number or total size of files that have been uploaded, so
theoretically, a patient user can fill your disks (even with the 200 KB per file
limit I mentioned above) by uploading many many files.

Another problem is that if a user uploads a file that has the same name as an
existing one, it will overwrite the old one. Thus, the previous message that
had the image will now have the new image instead of the old one. One solution
would be, instead of naming the files the same as the local file that the user
uploaded, to name them sequentially. But that was not a problem at my site, so
it's left as an exercise to the reader. :)

I have tested this on YaBB 1 Gold SP1.2, and my installation runs on Windows.
But nothing should have to be changed to make it work on other OSes. (I love
Perl :-)

If someone would like to package this as a proper mod, and redistribute it,
you are free to do so. Please just keep my name in the comments and credit me
for the original code.

This code is placed in the public domain, with no guarantee whatsoever. Use it
at your own risk.

I hope this is useful. Any comments or bugs can be sent to
jean_seb@videotron.ca, but I cannot guarantee I can work anymore on this since
it was meant as a one-shot deal to work on my board, and it works for me. Your
best bet to get a bug fixed is to fix it yourself and submit the modified
files to the public. If you make any such changes, please e-mail me to let me
know. Even though I might not be able to put any more time into this, I'm still
interested to see how people will add to it and use it.


Installation instructions
--------------------------

The upload.cgi script requires Perl, which you likely already have installed if
YaBB works at all. I believe it will run with almost any
version of Perl, but I have 5.6 . It also requires the CGI Perl module, which
you should also have if YaBB works.

You need to change a couple things in upload.cgi to make it work :
    * line 1, change the path (after '#!') to the path to perl on your machine
      (I have set it to a default that is valid on most machines)
    * line 62, change the path to where you want the images saved
      (can be relative, but must be web-accessible and must exist)
      (I set it to a directory that will be under an images directory of the
      root of your site if yabb is installed to the default location)
    * line 63, change the address to the web address of the folder you put on
      line 62.

Then, put the upload.cgi and upload.html files in the same directory as YaBB.cgi
or YaBB.pl.

Last thing, open up your ubbc.js (which is in the parent directory of the one
which contains YaBB.cgi and YaBB.pl) and change the image function (line 59 or
so) to this (you can copy-paste) :

function image() {
    var w = 450;
    var h = 220;
    if (screen.width) {
        var winx = (screen.width - w)/2;
        var winy = (screen.height - h)/2;
    }
    else {
        winx = 300;
        winy = 300;
    }

    var settings = 'width=' + w + ',';
    settings += 'height=' + h + ',';
    settings += 'top=' + winy + ',';
    settings += 'left=' + winx + ',';

    var win = window.open('<web path to upload.cgi>', 'bob', settings);
    win.window.focus();
}

and change the first argument to window.open (above) to be the path to
upload.cgi on your web server (start with http://, and be sure to keep
the single quotes around the path).