Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Show an error message when user tries to upload file other than jpg or gif

Posted on 2006-03-29
5
Medium Priority
?
179 Views
Last Modified: 2013-12-24
I have users uploading images to a site. I have it set up so that only jpg or gif files can be uploaded (in the cffile tag). If someone tries to upload a different file format, the CF error message shows. How can I show my own error message when this happens? I currently have an ImageUpload.cfm page and and ImageUploadAction.cfm page.

Thanks much!

IShiva
0
Comment
Question by:IShiva
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 16327327
IShiva,

Use a try catch block around your statements and catch the error.

Or allow all types of files, and then look to see what it is after the fact.

Regards
Plucka
0
 

Author Comment

by:IShiva
ID: 16333748
Thanks for the reply Plucka.

Can you provide some code for this? I have never used cftry or cfcatch before. Here is part of the code for the 2 pages I mentioned earlier.

Thanks!

PlayerImageAdd.cfm

<tr>
<td class="frame">
<cfform method="post" name="form1" enctype="multipart/form-data" action="PlayerImageAddAction.cfm?PlayerID=#URL.PlayerID#">
<table align="left">

<tr valign="baseline">
<td nowrap align="right">Player Image:</td>
<td><input type="file" name="PlayerImage" id="ul_path"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Add Image"></td>
</tr>
</table>
<input type="hidden" name="MM_InsertRecord" value="form1">
</cfform>
</td>
</tr>

PlayerImageAddAction.cfm

<cfset PlayerID = #URL.PlayerID#>

<cfquery datasource="newshs">
UPDATE #SESSION.Auth.tblPlayers# SET PlayerImage=


<cfif IsDefined("FORM.PlayerImage") AND #FORM.PlayerImage# NEQ "">
<cffile action="upload" filefield="PlayerImage" destination= "c:\inetpub\wwwroot\shacom\#Session.Auth.hsSport#\pictures\players" accept="image/jpeg, image/pjpeg, image/gif" nameconflict="makeunique">
<cfset UploadedFile = "#file.serverfile#">
'#UploadedFile#'
<cfelse>
 ''
</cfif>
WHERE PlayerID=#PlayerID#
</cfquery>

<cflocation url="PlayerEditForm.cfm?PlayerID=#PlayerID#">
0
 
LVL 18

Accepted Solution

by:
Plucka earned 2000 total points
ID: 16378904
IShiva,

<cftry>
    <cffile action="upload" filefield="PlayerImage" destination= "c:\inetpub\wwwroot\shacom\#Session.Auth.hsSport#\pictures\players" accept="image/jpeg,image/pjpeg, image/gif" nameconflict="makeunique" />

    <cfcatch type="any">
        <cfoutput>Sorry could not upload this file type</cfoutput>
    </cfcatch>
</cftry>

They type = "any" will catch any type of error occuring within the try block.


Regards
Plucka
0
 

Author Comment

by:IShiva
ID: 16418329
Sorry for the delay in responding.

I will give that a shot

Thanks

IShiva
0
 

Author Comment

by:IShiva
ID: 16425913
Well, that was pretty much pain free! Thanks a lot plucka!

Worked great

IShiva
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question