Verification of an uploaded file BEFORE upload - The Answer

Hello fellow CF Maniacs...
As many of us may have experienced, when someone uses a form
on a site to upload a file, it can be quite a pain to have to wait
for the file to be uploaded before it gets verified as the correct
file name or file format.
I set out on a quest to find a javascript solution to this
problem.
What I was looking for was a way for the actual filename
selected by the user, regardless of what directory structure
information was in the file field upon submission, to be verified
before the upload took place.
For instance, if the site were expecting a file called
'myfile.jpg', when the user clicked on the browse button to select
the file, the resulting string of text could be anything.
It might be 'C:\myfile.jpg' or
'D:\SomeDirectory\AnotherDirectory\YetanotherDirectory\myfile.jpg'
Worse yet, it might even be the wrong file entirely.
Up until now, I've always had to allow the file to be
uploaded and then verify the file was correct.
When you're getting large files from users, and even small
ones at times, this can be a 'patience issue' for the user. They
wait around for the file to be uploaded, just to be told 'Oops, you
sent the wrong file, please try again'.
After a few hours of trial and error, I came across an
unrelated javascript file that seemed like it would work for my
requirements. And it did. Yes, if the user has javascript disabled
there's the chance this wont work - but for those who have it
enabled, it could save a lot of bandwidth in uploads and reuploads,
and a lot of time for the user.
The following example can be used to create a page called
'testform.cfm'.
The only value in the following example form that you would
change is:
filename.ext = the filename and extension you require to be
selected (i.e. myfile.jpg or somefile.html)
This code will work 'out of the box' if you just want to put
a specific filename in the 'thefilename' field. However, this will
mean that everyone user uploading a file will be sending the same
filename as everyone else.
I wont go into how to get unique filenames for each user,
because that's not what this instruction page is for. If you need
unique filenames, there are a variety of ways to change the passed
value of 'thefilename' to accomodate them.
Enough yacking.. here's the code:
<!-- content of testform.cfm --->
<cfif parameterexists(field2) is 'no'>
<script language="Javascript">
<!--
function copyData(from,to) { to.value = from.value }
// -->
</script>
<form name="myForm" action="testform.cfm" method="post"
enctype="multipart/form-data">
<input type="file" name="field1"
onchange="copyData(this,document.myForm.field2)"
onKeyUp="copyData(this,document.myForm.field2)">
<input type="hidden" name="field2"
onchange="copyData(this.document.myForm.field1)"
onKeyUp="copyData(this,document.myForm.field1)"><input
type="submit" value="go">
<input type="hidden" name="thefilename"
value="filename.ext">
</form>
<Cfelse>
Field 2 is
<cfoutput>#field2#</cfoutput><Br><BR>
<cfset namelength = #LEN(thefilename)#>
<cfset actualfile = #RIGHT(field2, namelength)#>
Actual Filename picked on form was:
<cfoutput>#actualfile#</cfoutput><Br>
Looking for the filename:
<cfoutput>#thefilename#</cfoutput><Br>
<cfif #actualfile# is not '#thefilename#'>
File did not match - don't continue with upload
<cfelse>
File matched - continue with upload
</cfif>
</cfif>
Perhaps someone will come along and make this work even
better. But at least this works :)
Kudos,
eTeli.com

Oops.. perhaps I should explain what is happening when this
code is used.
First off, there is a file input field (field1).
Secondly there is a hidden field (field2).
What the code is doing, is taking whatever text appears in
field1 and automatically inserting it into the hidden field2 value.
When the form is submitted, the field1 value will be changed
by the server to some temporary value - which is of no use when
you're trying to find out the actual text that was in the field to
begin with.
But, since the hidden field has a 'copy' of that value, and
the hidden field doesn't get changed to a temporary one, you have
something to work with before the file gets delivered to the
server.
Pretty simple solution really.. too bad it took me hours to
find it.
I went through everything from using regex searches and finds
to trying to disable the submit button if the filename was
incorrect.
Everything else I tried failed.
Hope it works for you :)
eTeli.com

Similar Messages

  • Can I back up the files before doing the recovery?

    Hello
    If using the recovery disk to load windows (I have Windows Vista 32-bit) is it possible to save files (pictures, etc...) before wiping out these files on the hard drive?
    I have not backed up some files and cannot access windows to do this now...am wondering if I can back up the files before doing the recovery?
    Any help would be appreciated : )

    Hello
    You can try to start Vista in Safe mode. Start your notebook and press F8. Choose option to start OS in safe mode. When Vista starts connect external HDD or USB memory stick and copy all your data there.
    I have done this three weeks ago. I was not able to start Vista properly due to blue screen.

  • I have CS4 In design but when I try to open a certain file I get the answer that all plug in´s is not in my program. How can I update my plug ins?

    I have CS4 In design but when I try to open a certain file I get the answer that all plug in´s is not in my program. How can I update my plug ins?

    <moved from Downloading, Installing, Setting Up to InDesign>

  • My time machine is not working and the disk utilities cant repair it and is asking me to format the drive again. How can I backup the files before formatting the drive so that I don't lose my files?

    Hi
    My time machine hard drive has stopped working after the latest update and the Disk Utilities says,:
    Error: Disk Utility can’t repair this disk. Back up as many of your files as possible, reformat the disk, and restore your backed-up files."
    How can I back up my files before reformatting when I can't even open the drive's folder?
    Thanks for the help.

    I think my time machine is not working correctly and I dont know how to get it back... I really need to get back my photos!!!!!
    Exactly this was the way I USED to make restores of files and photos..
    but know I CANT!!!!
    When I am inside iPhoto y click on the Time Machine icon at the Dock and it goes to this...
    at my right side there are the backups but when i click them nothing happens they are like NOT CLICKABLE...
    PLEASEE!!! Help me!!

  • Back up your iCal files before applying the Mac OS X 10.4.4 Update

    It seems as though this sort of thing should not happen, but the mere application of the Mac OS X 10.4.4 Update - in small but noticeable ways - damaged my existing calendars, rendered a subscribed calendar effectively unsubscribed, and the Birthdays calendar present but empty. Neither of these calendars were actually removed: they just appeared devoid of data.
    Because I had previously backed up the calendars using the Back up Database… option in iCal before applying the update, I simply restored them to fix the issues in the standard calendars.
    To fix the subscription problem, I had to unsubscribe, then re-subscribe to that calendar.
    To fix the Birthdays calendar issue, I simply had to launch the Address Book, remove a birthday in one record, exit the edit mode, then paste it back in. Instantaneously, the Birthdays calendar was populated with data once again.
    Does anyone actually test these updates before they are released? [Facetious question, I know - but one does have to wonder…]
    PowerBook G4 12 867 MHz 640 meg 40 gig SuperDrive   Mac OS X (10.4.3)   What problem? I use the The Missing Sync for Palm OS

    You have limited options:
    1. If there is an Apple retailer nearby you can have them copy the update to a CD for you - usually at no or nominal charge.
    2. You can go to a local Mac user group (if there is one in your area) where they would be happy to provide a copy of the update for you on a CD at no or nominal charge.
    3. You can find another Mac user who has a high-speed connection and can download the update for you.
    4. You can call AppleCare and order a copy of the update on CD for a charge of (I think) around $9.95.
    5. You could find a Mac owner somewhere who would copy the update to a CD and mail it to you at any negotiated cost. However, do not solicit this assistance on these forums. Of course anyone reading this post could offer their help.
    Why reward points?(Quoted from Discussions Terms of Use.)
    The reward system helps to increase community participation. When a community member gives you (or another member) a reward for providing helpful advice or a solution to their question, your accumulated points will increase your status level within the community.
    Members may reward you with 5 points if they deem that your reply is helpful and 10 points if you post a solution to their issue. Likewise, when you mark a reply as Helpful or Solved in your own created topic, you will be awarding the respondent with the same point values.

  • Things needed to do before running the Answer File of the forest

    All of the following need or will be generated from the Answer File of the forest "mysite.com" but I am getting an error on NTDS. Working in Windows Server 2008 R2 SP1. 
    I have a file for NTDS without a file extension but it does not work:
    BUILTIN\Users: Special Access [RX]
    BUILTIN\Power Users: Special Access [RWXD]
    BUILTIN\Administrators: Special Access [A]
    NT AUTHORITY\SYSTEM: Special Access [A]
    CREATOR OWNER: Special Access [A]
    Also one for Drop without a file extension:
    BUILTIN\Users: Special Access [RX]
    BUILTIN\Power Users: Special Access [RWXD]
    BUILTIN\Administrators: Special Access [A]
    NT AUTHORITY\SYSTEM: Special Access [A]
    CREATOR OWNER: Special Access [A]
    Answer File of the forest:
    [DCInstall]
    ReplicaOrNewDomain="Domain"
    NewDomain=Forest
    NewDomainDNSName="mysite.com"
    ForestLevel="4"
    DomainNetbiosName="MYSITE"
    DomainLevel="4"
    InstallDNS="Yes"
    ConfirmGc="Yes"
    CreateDNSDelegation="No"
    DatabasePath="C:\Windows\NTDS"
    LogPath="C:\Windows\NTDS"
    SYSVOLPath="C:\Windows\SYSVOL"
    SafeModeAdminPassword="pass1"
    RebootOnCompletion="Yes
    The rest of the needed directories
    C:\Windows\NTDS.  File extension?
    C:\Windows\NTDS\Drop.  File extension?
    C:\Windows\System32\NTDS.dit
    C:\Windows\SYSVOL\
    C:\Windows\SYSVOL\domain\
    C:\Windows\SYSVOL\domain\DfsrPrivate\
    C:\Windows\SYSVOL\domain\Policies\
    C:\Windows\SYSVOL\domain\scripts\
    C:\Windows\SYSVOL\staging\
    C:\Windows\SYSVOL\staging\domain
    C:\Windows\SYSVOL\staging areas\
    C:\Windows\SYSVOL\staging areas\mysite.com\
    C:\Windows\SYSVOL\sysvol\
    C:\Windows\SYSVOL\sysvol\mysite.com\

    Yes. The Drop folder is not really used unless SMTP based replication is used.
    Enfo Zipper
    Christoffer Andersson – Principal Advisor
    http://blogs.chrisse.se - Directory Services Blog

  • Check and Verify USMT IMG file before formatting the system

    Hi Team,
    We are using 2 phase approach for migrating from XP to windows 8.1 U1 since we have Config manager 2012 R2. Its a refresh, replace and baremetal scneario
    So 1st TS will just do user state backup using ADK8.0 USMT and backup the data on SMP.
    2nd TS will format the system, install OS,install Apps and then restore USMT data from SMP
    I am looking for some way to check the usmt data on SMP for the system before system is formatted. Can anyone give some pointers to do that in 2nd task sequence? I want if data (img file) is not verified, system should not format and TS should fail.
    Regards,

    Hi,
    Do not use the option /c .
    If an errors occur during the capture process, the ScanState command will not continue to run and the TS will fail.
    For more information, please review the link below:
    ScanState Syntax
    http://technet.microsoft.com/en-us/library/dd560781(v=WS.10).aspx
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Read a text file before knowing the encoding

    Hi,
    I've wrote a AppleScript to adjust time delay of *.lrc file(txt file but different extension).I only got a messed up text, in other aspect, it works well. I understand applescript read the text file using the wrong encoding, but I can't just set the encoding to UTF-8, for it can be UTF-8 and it can be Shift-JIS, Big5 andGB18030 as well. I don't know how to open text without getting messed up and write the result to a new text file on desktop using UTF-8 encoding. Can anyone help me with this? Thanks in advance.
    Code:
    on run
      set _lrcFile to (choose file)'s POSIX path
      display dialog "Time to delay (sec):" with title "Adjust LRC Delay" default answer "-0.5"
      set _timeDelay to text returned of result
      try
      set _timeDelay to _timeDelay as real
      on error
      display dialog "Input must be a real" with title "Error" buttons {"Stop"} default button "Stop"
      error number -128
      end try
      set _paraList to paragraphs of (read POSIX file _lrcFile)-->I don't know how to read text file properly here.
      set _newLrc to ""
      repeat with _para in _paraList
      set _timecode to do shell script "sed 's/\\[\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}.[0-9]\\{2\\}\\)\\]\\(.*\\)/\\1 \\2/'<<<" & quoted form of _para
      if _timecode as string is not (contents of _para) then
      set _timecode to words of _timecode
      set _min to (item 1 of _timecode) as integer
      set _sec to (item 2 of _timecode) as real
      set _sec to _sec + _timeDelay
      set _min to _min + _sec div 60
      set _sec to _sec mod 60
      set _sec to (round (_sec * 100)) / 100
      if _min < 10 then
      set _min to "0" & _min as string
      else
      set _min to _min as string
      end if
      if _sec < 0 then
      set _sec to "00.00"
      else if _sec < 10 then
      set _sec to "0" & _sec as string
      else
      set _sec to _sec as string
      end if
      if (count of _sec) < 5 then
      set _sec to _sec & "0"
      end if
      set _lyrics to do shell script "sed 's/\\[\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}.[0-9]\\{2\\}\\)\\]\\(.*\\)/\\3/'<<<" & quoted form of _para
      set _newLrc to _newLrc & "[" & _min & ":" & _sec & "]" & _lyrics & return
      else
      set _newLrc to _newLrc & contents of _para & return
      end if
      end repeat
      -->write _newLrc to destop here (using UTF-8 encoding)
    end run
    Sample of *.lrc and the result after delaying 0.5s.

    Hope this post will help people doing their homeworks...
              StringBuffer tmpBuffer = new StringBuffer();
              try {
                   URL url = new URL("http://.../test.txt");
                   URLConnection urlconnection = url.openConnection();
                   long l = urlconnection.getContentLength();
                   tmpBuffer.append("Content Length = " + l);
                   BufferedReader in =
                        new BufferedReader(new InputStreamReader(url.openStream()));
                   String line;
                   while ((line = in.readLine()) != null) {
                        tmpBuffer.append("\n" + line);
                   in.close();
              } catch (Exception e) {
                   //System.out.println(e.toString());
              if (tmpBuffer != null) {
                   wdContext.currentContextElement().setZoneMessage(
                        tmpBuffer.toString());

  • Save into a file before exiting the program

    Hi All,
    I am developing a java project. It is a console application.
    Initially the program loads content of a file(customer.txt) into an ArrayList.
    Then it gives 3 options:-
    1. Add a Customer
    2. Delete a Customer
    3. Save and Exit
    The changes add or delete are made in the ArrayList.
    The ArrayList is saved back to the customer.txt only when we select the option 3.
    It works fine.
    But instead of exiting the application using option 3, if we close the eclipse window or restart the computer, the changes are not saved to the file.
    So could you please suggest me how we can save the changes in such situations.?

    - Create a class that extends Thread
    - in the run() method place the code that saves your data
    - in your initialization create an instance of your Thread class but do not start it - instead register the object as a shutdown hook (use Runtime.getRuntime().addShutdownHook()).
    When your application terminates the VM will kick off your thread, which should save your data. You may have to experiment a little to get it working right. Remember that only a normal termination signal will allow the VM to continue running so that it can execute your shutdown thread - a kill signal will stop the VM, as will calling Runtime.halt().
    (Edit: note also that this may not work in Eclipse - I've seen problems running shutdown hooks when testing an application under Eclipse.)
    Edited by: PeteFord on Nov 17, 2008 1:39 PM

  • I tried asking before, and the answer I got took me to place, but nothing was there. Basically, clicking my bookmark tab or the star as NO affect, and I cannot bookmark.

    Basically, clicking my bookmark tab or the star as NO affect, and I cannot bookmark. I am about ready to just ditch firefox all together. Can someone help? I want to keep it, cuz it's the fastest, but I want my normal funcitons to work, or it's pointless.

    There 5 ways to save a new Bookmark in Firefox: <br />
    1. {Ctrl + D} <br />
    2. Right-click and select Bookmark this Page. <br />
    3. Bookmarks > Bookmark this Page <br />
    4. Double-click the Star that is on the right side of the Location bar. <br />
    4a. (A single-click on the Star will save the new Bookmark to the Unsorted Bookmarks folder.) <br />
    5. Letf-click and drag the website image ''(Favicon)'' in the URL bar (or on the active tab) into the Sidebar view of Bookmarks {Ctrl + B} <br />
    or to the Bookmarks menu bar item ''(the drop-down will open)'' and then onto the drop-down listing of your bookmarks and folder of bookmarks ''(folders will open)''<br />
    or onto the Bookmarks Toolbar - the new bookmark will be saved when you release the left mouse button

  • Since I downloaded Adobe Reader 11.0.07 I have been totally unable to print any PDF files using my Dell 1720 laser printer - I just get a blinking "error" light on the printer, no other error messages . I never had a problem printing PDF files before down

    Since I downloaded Adobe Reader 11.0.07 I have been totally unable to print any PDF files using my Dell 1720 laser printer - I just get a blinking "error" light on the printer, no other error messages . I never had a problem printing PDF files before downloading the new Reader version. Suggestions? Thank you.

    Hi,
    Which version of Adobe Reader were you using earlier when printing using Dell printed was working fine?
    Thanks,
    Shakti K

  • Offline updates mechanism: how many times can you use it before corrupting the image(wim)?

    Hi,
    As title mentions: "how many times can you use sccm 2012 offline updates for the wim file before corrupting the image(wim)"?
    J.
    Jan Hoedt

    In my experience the offline servicing feature is only OK and too unreliable for production.
    Gerry Hampson | Blog:
    www.gerryhampsoncm.blogspot.ie | LinkedIn:
    Gerry Hampson | Twitter:
    @gerryhampson

  • HT1918 How do I change my verification questions? I know my password but forgot the answers to these questions and therefore cannot purchase any new apps. How can I change them?

    I have recently changed devices from ipod touch to a new iphone 4s. Since this is now a new device..I am required to answer two verification questions. Only, i have forgotten the answers to them. Now I am in a situation where I cannot purchase any new apps.

    Check the AppleCare number for your country here:
    http://support.apple.com/kb/HE57
    Call them up, and let them know you would like to be transferred to the Account Security Team.

  • To what folder do I upload the google webmaster verification file too?

    Trying to verify my website on BC so I can get the sitemap searched.
    WHICH folder do I upload the google webmaster verification file too?
    Thanks!

    Do not use that one, Use the meta method - Better.

  • Question about image preview in client side before upload the image file to server

    Hi everyone:
    My project has an image upload function. Currently it only display a fileupload component, after user press OK, the file will upload to server, but there's no preview before user press OK.
    I want it can show the preview, I know that I can upload the file to a temporary directory on server then show that image to client, but in this way will cause strain on server. Is there any other ways to preview the image? Like using JavaScript? Thankyou.

    Stuck with BMP

Maybe you are looking for