Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cffile - limiting uploads to gif and jpg only

Status
Not open for further replies.

peter11

Instructor
Mar 16, 2001
334
0
0
US
I have set an upload site with cffile but I need to create a javascript or something to limit the uploads to Jpg and gif only. I do not want to set this on the server because I have other upload sites that I want to limit to pdf's.

Can anyone help me with this
Thanks
 
you can specify that in your cffile tag like this...
<CFFILE ACTION=&quot;Upload&quot;
FILEFIELD=&quot;FileContents&quot;
DESTINATION=&quot;c:\web\uploads\&quot;
ACCEPT=&quot;text/html&quot;
NAMECONFLICT=&quot;MakeUnique&quot;>

use ACCEPT=&quot;image/gif, image/jpg&quot; that should do it.
 
Is there a way to create a javascript on to validate that the image is a gif or a jpg before it is submitted to the server?
 
You could try this.... seems a bit long now, but should do the validation you want. The consequences of a user renaming...? Pass!

<HTML>
<HEAD>
<SCRIPT language=&quot;JAVASCRIPT&quot;>
function CheckPiccy()
{
var fileName=document.UPLOADING.THEFILE.value.toLowerCase();

if ((fileName.indexOf(&quot;.gif&quot;) == -1 ) && (fileName.indexOf(&quot;.jpg&quot;) == -1 )&&(fileName.indexOf(&quot;.jpeg&quot;) == -1 ))
{
alert(&quot;Please only upload a valid image file&quot;);
}
else
{
document.UPLOADING.submit()
}
}
</SCRIPT>
</head>
<BODY>
<FORM name=&quot;UPLOADING&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;>
<INPUT type=&quot;FILE&quot; name=&quot;THEFILE&quot;>
<INPUT type=&quot;BUTTON&quot; onClick=&quot;CheckPiccy()&quot; value=&quot;Upload!&quot;>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top