• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Processing uploaded files

Enthusiast ,
Feb 01, 2008 Feb 01, 2008

Copy link to clipboard

Copied

I need to upload photos to a site, I want to make sure that they are only JPG files uploaded, plus restrict the size.

Is there anyway to check the filesize and type before uploading? Or can somebody upload a 20meg EXE file that would hog our bandwidth?

Also, how do I check the file extension to make sure it's JPG? When I look at it I get TMP, and if I save it I seem to have to specify an extension?

Thanks

Mark
TOPICS
Advanced techniques

Views

540

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2008 Feb 02, 2008

Copy link to clipboard

Copied

Hi ACS LLC,

Please use the following reference sites. You can check the size of the file once the file uploaded or during the time of upload also and then you have to set custom message to user regarding the size of the file.

Reference 1: Checks the file size once uploaded
http://www.bennadel.com/blog/670-Ask-Ben-Limit-File-Upload-Size-In-ColdFusion.htm

Reference 2: The check is performed before uploading the file
http://tutorial120.easycfm.com/

And to ensure the file type you need to use another attribute in CFFILE tag called accept = "image/jpg"

Akbarsait
Chennai ColdFusion UserGroup, India
http://akbarn.wordpress.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

Thanks.

The filesize check was very handy (I should have figured that out myself from the DOCs)

The only issue I have is with accept = .. problem is that if I only accept JPG's it appears to throw a CF error if anything but that is uploaded.. is there a way to pick this up so I can process the error appropriately?

Thanks

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

I actually came across another issue

We upload two images from the previous page, so by checking the cgi content size it does not work because if we want to restrict to 100k per file it actually adds up both images, so it was have a 95k and an 80k both are technically acceptable, but the total is under 100k for each. I could make it stop at 200k , but that then allows users to manipulate the upload, they could upload a 190k and go back and upload another 190k in the 2nd picture.

I was also just told by somebody that is still uploads the file in order to get the file size?

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

ACS LLC wrote:
> Thanks. The filesize check was very handy (I should have figured that out
> myself from the DOCs) The only issue I have is with accept = .. problem is
> that if I only accept JPG's it appears to throw a CF error if anything but that
> is uploaded.. is there a way to pick this up so I can process the error
> appropriately? Thanks Mark
>

use cftry/cfcatch - details are in the docs


---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

ACS LLC wrote:
> I actually came across another issue We upload two images from the previous
> page, so by checking the cgi content size it does not work because if we want
> to restrict to 100k per file it actually adds up both images, so it was have a
> 95k and an 80k both are technically acceptable, but the total is under 100k for
> each. I could make it stop at 200k , but that then allows users to manipulate
> the upload, they could upload a 190k and go back and upload another 190k in the
> 2nd picture. I was also just told by somebody that is still uploads the file
> in order to get the file size? Mark
>

in your case i would probably:
[all the below on the action page, obviously]
1) check the CGI.CONTENT_LENGTH to see if it is significantly larger
than ([allowed file size]x[number of files being uploaded])+[size of
form page]
2) if it is NOT significantly larger then use CFFILE.FILESIZE after each
upload (in a cfloop, presumably) to check exact size of each file and
delete the ones found to be too large.

hth


---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 03, 2008 Feb 03, 2008

Copy link to clipboard

Copied

LATEST
Good idea.

I was told however that to get that CGI variable that the server has to upload anyway, so nothing gained. I am testing locally right now so that is difficult to disprove. I'll try some code on the server and upload a LARGE file

Thanks

Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation