Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 07:47:25 AM

Pages: [1]   Go Down
  Print  
Author Topic: Making web polls and image uploading tools  (Read 296 times)
Dannny
Spacescooter Operator
*****
Offline Offline

Posts: 40


WWW
« on: April 02, 2003, 09:06:00 PM »

what would you advise for web polls?

Also does anyone know how to create a image only uploading script PHP or otherwise, here is what i have at the moment but as you can see if you press browse you also can have the option to upload html/htm and other files, how do you create a image ONLY uploader. Link:

http://digitalarmynetwork.net/upload.php
Logged
Ed
Berserker Poster
*****
Offline Offline

Posts: 5208



WWW
« Reply #1 on: April 02, 2003, 10:17:00 PM »

I found this on the web.. might do the trick for you, but to be 100% sure you will need to fidn somethign to check it on the server side.:

 
code:
 This shoulddo the trick and only allow users to submit filenames with certain extensions:


<script language="javascript">
var AllowExtensions = new Array("jpg","gif","png")
var FileOK = false;

function checkExtension() {
    //we assume that Extension is false;
    var ExtensionOK = false;

    // retreive the value of the file-box
    var fieldVal = document.forms[0].elements.pic.value;

    // loop through array of allowed extensions
    for(var i = 0; i < AllowExtensions.length; i++) {
         if(AllowExtensions == fieldVal.substring(fieldVal.length - AllowExtensions.length, fieldVal.length)) {
              // The choosen extension matches one of the allowed ones
              ExtensionOK = true;
         }
    }

    if(ExtensionOK == false) {
         // file extension didn't match any of the
         // allowed ones, signal user with an alert
         // unfortunately we're not able to reset
         // the file-box
         alert(fieldVal + " is not an allowed filetype.");
    }

    // update the valid marker for the current file
    FileOK = ExtensionOK;
}
</script>

<form name="testForm" action="<% = Request.ServerVariables("PATH_INFO") %>" method="get" onsubmit="return FileOK;">
    <input type="file" name="pic" accept="image/gif" onchange="checkExtension();"><br>
    <input type="reset">
    <input type="submit">
</form>

Hope this helps!

- Ed
Logged

Dannny
Spacescooter Operator
*****
Offline Offline

Posts: 40


WWW
« Reply #2 on: April 02, 2003, 11:51:00 PM »

i've been browsing through that page, the coding is a bit dodgy

This:
 
code:
if(ExtensionOK == false) {
        // file extension didn't match any of the
        // allowed ones, signal user with a confirmation
        // and clear the form field
        if(confirm(fieldVal + " is not an allowed filetype.")) {
               document.forms[0].reset();
             }
   }

Should replace:

 
code:
 if(ExtensionOK == false) {
         // file extension didn't match any of the
         // allowed ones, signal user with an alert
         // unfortunately we're not able to reset
         // the file-box
         alert(fieldVal + " is not an allowed filetype.");
    }


 
 [ April 03, 2003, 08:54 AM: Message edited by: DigitalArmyNetwork ]
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: