Uploading files to your webpage in WhizBase

AID: 1870
  • Status: Published

1490 points

  • ByNurAzije
  • TypeTutorial
  • Posted on2009-10-27 at 06:04:31
Have you ever wanted to upload your files to your hosting, or have you ever want to make a simple images gallery and let the visitors upload their pictures.

In this tutorial I will show you how simple is to write a script for uploading your files online (with no need for complicated web scripts like ASP or PHP) by using WhizBase. I have been a WhizBase developer for 6 months now, I also have been a PHP developer for 7 years.

Simple HTML uploading form

If you want to upload images you will need a form, it is made in pure HTML, a page where you click on "Browse" and select the file you want to upload. Fortunately HTML provides us with the elements, we do not need to write scripts to list files on our computer.

<html>
<head>
<title>Upload an Image</title>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form action="upload.wbsp" method="post" ENCTYPE="multipart/form-data">
Select file (*.jpg;*.gif - max. 100KB): <input type="file" name="image" size="20"> <input type="submit" name="sButt" value="Upload">
</form>
</body>
</html>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window



Let take a look in some important elements in this code, first the Form tag, without it our code will not work, the form tag must contain information like action (where to send the file data), method (there is two general methods - get and post; when sending files use post) and enctype(there is a lot of encoding types, multipart/form-data is used for uploading files).

Also we need to use the input of type file, that input is the one which let us browse our computer files. Last is the submit input, it is the button which people will click to send or upload the file.

Save this file as index.htm and put it in a folder so you do not loose it.

The butter of the work

Now we want to make the server-side file, it is the script which takes the file, save it on the hosting server.

[FormFields]
WB_AllowMultipart=T

[Upload]
WB_Disallow=![jpg,gif,png,bmp]
WB_UploadDir=/
WB_Overwrite=T
WB_MaxFSize=102400

<!--WB_BeginTemplate-->
<html>
<head>
<title&rt;File uploaded</title>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
Your file have been uploaded!
</body>
</html> 
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:

Select allOpen in new window



OK, do not get afraid, it is not complicated as it seems, I will explain every line before the HTML tag, make yourself a coffee or a tea and sit down and read.

Let me explain first that what is used as a scripting language is WhizBase Server Pages. WhizBase is simple but powerful scripting language on the server-side, it is made for non-programmers to simplify creating database-driven websites without the need for high experience in high-level programming languages. It is not a programming language but it can do everything you need for a web page. You will need to have WhizBase installed on your server, for more information please visit WhizBase.

Now in English, it is a scripting language for everyone, simple and easy for you to use. Let me show you how.

The header section

Every WBSP page have a header, it is a place where we put information needed by the server, everything we write in this section will not appear in our page. This section contains the variables that are essential for processing WBSP file. Here you put information about the database, recordset, template, error template, log file, redirection, etc.

In the code we have [FormFields] which is a tag giving a notice to the WhizBase engine to start interpreting the main commands of the WBSP file.

Then we have WB_AllowMultipart = T. This variable controls if the current WBSP page will accept uploaded files (sent by client using multipart form). If this variable is set to TRUE WhizBase will accept and process uploaded files. This is a security measure so WBSP processes and stores the files that are uploaded.

The second tag is [Upload] which is a notice for the WBSP engine to start receiving information about the uploading process. Now ask yourself, do you want allow anyone to upload viruses or a porn dialer on your server? If no, you need to use WB_Disallow=![jpg,gif,png,bmp], which tells the WBSP engine that we do not want users to be able to upload any file, we only want images. This tag disallows every file which does not have one of the listed extensions.

Where do you want to put your pictures, you need an upload directory, so we use WB_UploadDir=/, this variable defines the name of the directory on the server where WhizBase will save files uploaded using current WBSP file.

Do you want to overwrite your image? WB_Overwrite=T is a variable which defines if the file with same name that already exists on the server will be overwritten by newly uploaded file. We will use T as True. If you define it as F (False) WhizBase will generate a unique file name for the new one and save it like that.

If you do not want visitors to block your server, you need to limit their file's upload size, so you use WB_MaxFSize=102400 which is a variable which defines the maximum size (in bytes) of a single file that can be uploaded using current WBSP file. We have entered 102400 bytes.

Finally we put <!--WB_BeginTemplate--> to let the server know that now we are starting the body section, where we put our HTML code and what we want to show for visitors.

As you see, we can control everything when uploading files. And that how you simply make an upload form which works without the need of PHP or ASP.

For more information about WhizBase please visit WhizBase site or contact me on NurAzije [at] Gmail [dot] com.

NurAzije is a PHP and WhizBase programmer, who at the time of article publication is working in partnership with WhizBase on several projects.
Asked On
2009-10-27 at 06:04:31ID1870
Tags

uplaod

,

whizbase

,

simple HTML

,

server-side scripting

Topic

Scripting Languages

Views
935

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Scripting Languages Experts

  1. mplungjan

    145,789

    Master

    0 points yesterday

    Profile
    Rank: Savant
  2. Ray_Paseur

    91,292

    Master

    0 points yesterday

    Profile
    Rank: Savant
  3. billprew

    63,376

    Master

    0 points yesterday

    Profile
    Rank: Genius
  4. RobSampson

    54,636

    Master

    0 points yesterday

    Profile
    Rank: Genius
  5. DaveBaldwin

    51,700

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  6. sedgwick

    43,950

    1,600 points yesterday

    Profile
    Rank: Genius
  7. leakim971

    43,184

    0 points yesterday

    Profile
    Rank: Genius
  8. dgofman

    36,400

    0 points yesterday

    Profile
    Rank: Genius
  9. COBOLdinosaur

    28,424

    0 points yesterday

    Profile
    Rank: Genius
  10. woolmilkporc

    24,200

    0 points yesterday

    Profile
    Rank: Genius
  11. ozo

    20,600

    0 points yesterday

    Profile
    Rank: Savant
  12. Qlemo

    19,984

    2,000 points yesterday

    Profile
    Rank: Genius
  13. chaituu

    19,100

    0 points yesterday

    Profile
    Rank: Sage
  14. tagit

    19,000

    0 points yesterday

    Profile
    Rank: Genius
  15. farzanj

    18,550

    0 points yesterday

    Profile
    Rank: Genius
  16. nap0leon

    15,094

    0 points yesterday

    Profile
    Rank: Sage
  17. paultomasi

    14,700

    0 points yesterday

    Profile
    Rank: Master
  18. StingRaY

    13,136

    0 points yesterday

    Profile
    Rank: Wizard
  19. jason1178

    13,044

    0 points yesterday

    Profile
    Rank: Genius
  20. HainKurt

    12,350

    0 points yesterday

    Profile
    Rank: Genius
  21. HonorGod

    11,600

    0 points yesterday

    Profile
    Rank: Genius
  22. ahoffmann

    11,136

    0 points yesterday

    Profile
    Rank: Genius
  23. basicinstinct

    10,800

    0 points yesterday

    Profile
    Rank: Genius
  24. leew

    10,030

    0 points yesterday

    Profile
    Rank: Savant
  25. ChrisStanyon

    9,864

    0 points yesterday

    Profile
    Rank: Sage

Hall Of Fame