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`](https://developer.mozilla.org/en-US/docs/HTML/Element/input#attr-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,
Sas
LVL 1
sasnaktivAsked:
Who is Participating?
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

0
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?
Sas
0
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?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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.
dropzone.js
0
Leonidas DosasCommented:
Not this code but your code html +script
0
sasnaktivAuthor Commented:
Okay, Now you have everything.

The HTML
<!DOCTYPE html>

<title>DropZ</title>

<!--<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>
</td></tr></table> 

Open in new window


The PHP
<?php
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"]);

$photoName_A=$newNAME_A.'.'.$fileTYPE;

$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

0
Leonidas DosasCommented:
Check this simple example:
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/dropzone.js"></script>
	<style>
	.dropzone{
	width:720px;
	height:184px;
	border:solid black 1px;
	
	}
	</style>
</head>
<body>
	<form action="/file-upload" class="dropzone" id="myAwesomeDropzone">
  <div class="fallback">
    <input name="file" type="file" multiple />
  </div>
</form>
<script>
Dropzone.options.myAwesomeDropzone = {
  paramName: "file", // The name that will be used to transfer the file
  maxFilesize: 2, // MB
  acceptedFiles:"image/jpeg,image/png,image/gif",
  
};

</script>
</body>
</html>

Open in new window

0

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????
Sas
1
David KellyWeb developerCommented:
Hit one of the "Best Solution" buttons (white with a green outline) at the bottom of any of Leonidas answers.
0
sasnaktivAuthor Commented:
There are NO SUCH BUTTONS!
Just a ridiculous blue button that says "Was this helpful"
Why is EE making things so difficult?
So how about a real SOLUTION?
0
Kyle SantosCustomer RelationsCommented:
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.
http://support.experts-exchange.com/customer/portal/articles/2527982-how-do-i-close-my-question-

Let me know if you need anything else.

Regards,

Kyle Santos
Customer Relations
0
sasnaktivAuthor Commented:
Leonidas.
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,
Sas
1
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.