How can 'dropzone.js' limit the type of file for upload?

Hi Guys,
I really don't have much knowledge of ".js". And part of the problem is that I don't even understand the instructions provided by the author.

I'm trying to limit the file upload to files with the following extensions: ".png,.jpg,.jpeg,.gif".

The default setting in dropzone.js is (acceptedFiles: null,). Unfortunately, with that setting, visitors can upload all kinds of nasty files. That's not something anybody in their right mind wants.

Below is the section of code in dropzone.js which is supposed to limit the type of file uploaded as well as the instructions that preceed it.  Anything other than "null" crashes the script. I've tried all kinds of variations on the example provided with absolutely no success. You can see my attempts on lines 13, 14 & 15

So, what will make this work???

         * The default implementation of `accept` checks the file's mime type or
         * extension against this list. This is a comma separated list of mime
         * types or file extensions.
         * Eg.: `image/*,application/pdf,.psd`
         * If the Dropzone is `clickable` this option will also be used as
         * [`accept`](
         * parameter on the hidden file input as well.
        acceptedFiles: null,    // I've tried everyone of the following with unsuccessful results. So what's the right way to do this? //
//        acceptedFiles: image/*,application/pdf,.psd
//        acceptedFiles: image/*,.png,.jpg,.jpeg,.gif,
//        acceptedFiles: .png,.jpg,.jpeg,.gif,

Open in new window

Any enlightment is appreciated,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leonidas DosasCommented:
Try with this:
acceptedFiles: "image/jpeg,image/png,image/gif"

Open in new window

sasnaktivAuthor Commented:
Thank you Leonidas,
I just dropped your code in, and like everything else I've tried the script crashes.
Got any other ideas?
Leonidas DosasCommented:
Have you check the maxFilesize property to have null setting? or the uploaded file not exceed the maxFilesize setting value if it's not null? Could you post the configuration dropzone code?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sasnaktivAuthor Commented:
Thanks again. Your attention is greatly appreciated.
I'm not having a problem with maxFilesize -- that functions just as it should. When I attempt to alter "acceptedFiles:" the script just comes up blank as though it drops dead and gives me a blank window.  I've attached the file as requested.
Leonidas DosasCommented:
Not this code but your code html +script
sasnaktivAuthor Commented:
Okay, Now you have everything.

<!DOCTYPE html>


<!--<form action=\"Upload.php\" class='dropzone'></form> -->
<!-- Note, for some strange reason the <form action=" must be in this code at the top and the bottom. -->
<table border=0 ><tr><td width=580 height='272' Valign=top align=center style='color:#da0211; font-size:27px; font-family:Arial, Verdana, Helvetica, sans-serif;font-weight:bold;'> 
<script src="dropzone.js"></script>
<link rel="stylesheet" href="dropzone.css">
<form action='Upload.php' class='dropzone' ></form>

Open in new window

if (!$_FILES) {
	$_FILES = array('file' => array("name" => "dummy.txt", "tmp_name" =>"temp"));

//~~~~~~~~~~~~~~~~~~~BEGIN CREATING UNIQUE PHOTO NAME~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// $M_ID=$_REQUEST['M_ID'];
$M_ID='31';   // use this for testing

$time = microtime(true);
$tMicro = sprintf("%03d",($time - floor($time)) * 1000);   
$newNAME_A = "Mb_$M_ID".'_'.gmdate('ymdHis', $time).$tMicro.'_A';
//~~~~~~~~~~~~~~~~~~~END CREATING UNIQUE PHOTO NAME~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

// Begin setting variables
$fileSIZE = basename($_FILES["file"]["size"]);
$fileTYPE = basename($_FILES["file"]["type"]);
$fileNAME = basename($_FILES["file"]["name"]);
$fileTEMP = basename($_FILES["file"]["tmp_name"]);


$target_dir = "../../W_Mb/Mb_PHOTOS/";

$target_dir = $target_dir . $photoName_A;

$filename = "";
// End setting variables

    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_dir)) {
		$filename = basename($_FILES["file"]["name"]);


Open in new window

Leonidas DosasCommented:
Check this simple example:
<!doctype html>
<html lang="en">
	<meta charset="UTF-8">
	<script src=""></script>
	border:solid black 1px;
	<form action="/file-upload" class="dropzone" id="myAwesomeDropzone">
  <div class="fallback">
    <input name="file" type="file" multiple />
Dropzone.options.myAwesomeDropzone = {
  paramName: "file", // The name that will be used to transfer the file
  maxFilesize: 2, // MB


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sasnaktivAuthor Commented:
Thank you! Thank you! Thank you!
You are "myAwesomeDropzoneGUY"

It would have been nice if the author of Dropzone wrote better instructions in the first place...

It would also be nice if I could figure out how to award you with the 1,000 points that you deserve. It seems that EE has made some changes (certainly not for the better) since the last time I used it.  Where's the damn button????
David KellyWeb DeveloperCommented:
Hit one of the "Best Solution" buttons (white with a green outline) at the bottom of any of Leonidas answers.
sasnaktivAuthor Commented:
Just a ridiculous blue button that says "Was this helpful"
Why is EE making things so difficult?
So how about a real SOLUTION?
Kyle SantosQuality AssuranceCommented:
Hi sasnaktiv,

On the left side of this page there should be a progress bar explaining what action you need to take next to close this question.  In most cases, you should be able to mark a comment as helpful, then click 'I have my answer' on the progress bar on the left, and then the Best Solution button will appear on the comment you want to accept as the solution.  Note: marking multiple comments as helpful will distribute points evenly to other experts.  

For more information on this new process please see this support article with steps and screen shots of the process.

Let me know if you need anything else.


Kyle Santos
Customer Relations
sasnaktivAuthor Commented:
Sorry this took so long to award you your well deserved points.  EE new method is next to impossible to use. It was one of the dumbest things they ever created. Frankly it sucks! And wasted quite a bit of my precious time. They should stop trying to impress each other and go back to the way it was.

Thanks again Leonidas,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.