July 30, 2010, 09:19:25 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Common questions answered here !
 
   Home   Help Search Login Register  
Pages: 1 2 [3]   Go Down
  Print  
Author Topic: File Type Validation  (Read 11890 times)
St03mp
Newbie

Offline Offline

Posts: 16


« Reply #30 on: February 19, 2008, 09:52:33 pm »

Ok, this might be exactly what I was looking for, but could someone please explain step by step where I put this code, to validate my file upload?

At this moment I have a form with a file upload field, name: upload
Scripts: none.

And a submit button, name: send
Scripts: ff_validate_submit

How do I continue from this point?
Logged
beginner
Newbie

Offline Offline

Posts: 9


« Reply #31 on: September 14, 2009, 01:23:01 pm »

Well, I finally gave in and decided to make this work... Here is what I came up with (modified a little to make a better example).

This code validates uploaded files to make sure that they are an acceptable file type.

The following was placed in my form's "Submit Pieces"->"End Submit"->"Custom" field:
Code:
// load the standard Facile Forms library
$this->execPieceByName('ff_InitLib');

function uploadOk($name, $extensions, $optional=false)
{
    $filename = ff_getSubmit($name);
    if ($filename)
    {
        $extension = strtolower(substr(strrchr($filename, "."), 1));
        if (in_array($extension, explode(',', $extensions))) return true;
        unlink($filename);
        return false;
    } // if
    return $optional;
} // uploadOk

if (!uploadOk('filePhoto1','jpg,gif,png',false) || !uploadOk('filePhoto1','jpg,gif,png',false))

    $this->status = 1002; // use any value > 1000 as private errorcode
    $this->message = "Incorrect File Type";
    return;
}

The fields that I am checking are called "filePhoto1" and "filePhoto2". you should change these to he name of the fields that you are using.

I have jpg, gif, and png as valid file types. Any other files types will be rejected (deleted actually). The big thing I changed in this version compared to previous versions was I call "strtolower()" while extracting the extension of the uploaded file. This means that if someone uploads a file called "myfile.JPG", it will not be rejected as it would without that call.

A BIG Thank You to everyone who has helped out in this thread (even those asking questions for clarification).

I hope this helps someone else in the future! Smiley

could anybody post a xml?
Because i could not manage it.
Logged
andrewvanmarle
Administrator
Full Member
*****
Offline Offline

Posts: 169



« Reply #32 on: September 15, 2009, 02:16:49 pm »

Maybe you should send chiefgofor a pm, he seems to have created the file you want...
Logged

Andrew

Please read the forum rules first!
Please do not use PM for generic questions!
Question regarding breezing forms? read this
beginner
Newbie

Offline Offline

Posts: 9


« Reply #33 on: September 15, 2009, 04:40:58 pm »

I did, but PM is not like E-Mail, so i dont know if he is still using that Forum.
Looking forward to get a working xml.

:-)
Logged
Pages: 1 2 [3]   Go Up
  Print  
 
Jump to:  

Powered by SMF © 2001-2006 Lewis Media
| Terms of Use | Privacy | Sitemap |