File Extension Validation

Hi,
I've created an upload form which is all working fine.
To reduce coding I've given the user an option of chosing the type of file they want to upload, once they've cliked on the chosen file type a URL parameter is past stating the file type.
What I want to do is have an error message is the string of the upload file doesn't contain the extension that matches the file extension.
I had a stab in the dark with this coding but it doesn't work and I can see why.
$error = array();
$pos = strpos($_GET['type']);
if ($pos === false) {
          $error['urlError'] = 'This is not a JPG, please reload the upload page and chose the correct file format';
//If no errors, process form//End Error Messages
if (!$error) {
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO files (ID, username, file_type, url, `date`, Uploader, email) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['ID'], "int"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['file_type'], "text"),
                       GetSQLValueString($_FILES['url']['name'], "text"),
                       GetSQLValueString($_POST['date'], "text"),
                       GetSQLValueString($_POST['Uploader'], "text"),
                       GetSQLValueString($_POST['email'], "text"));
etc
Any ideas would be much appreciated.
Cheers

declare
-- Local variables here
CURSOR c_get_file IS
     select t.blob_content from sr_docdb.document_upload t
WHERE t.name = 'F24972/Test.docx';                     
          v_content BLOB;
          v_amount INTEGER := 8; --8 bytes
     v_offset INTEGER := 1;
     v_file_header RAW(100);
     v_docx_binary RAW(20);
     v_docx_char CHAR(30);
begin
-- Test statements here
SELECT a.magic_number --Data type is RAW
     INTO v_docx_binary FROM document_extension_amy a
     WHERE a.document_extension_id = 8;
     htp.p('v_focx_binary: '||v_docx_binary); htp.br;
     OPEN c_get_file;
     FETCH c_get_file INTO v_content;
     CLOSE c_get_file;
     dbms_lob.read(lob_loc => v_content, amount => v_amount, offset => v_offset, buffer => v_file_header);
     htp.p('v_file_header: '||v_file_header);
--This section can be made as a function
     IF V_FILE_HEADER = v_docx_binary THEN
          HTP.P('DOCX');
          ELSE
          htp.p('OTHERS');
          END IF;
end;
This is a .tst file. The principal is to read from the BLOB content and compare that with the HEX value of DOCX. But for other file types, it is similar but may not be the same. As some files have the unique magic number of not 8 bytes.
and like .JPG, the magic number is FF D8 FF E0 xx xx 4A 46 49 46 00. the xx xx can be any hex value.
Is there anything that needs improvements? Please point out! Many thanks!

Similar Messages

  • Dreamweaver CC and Windows 8.1 - Can't Find A Valid Editor For This File Extension

    Was running the latest version with no issues and then I loaded Office 2013 .. Now when I am in the remote site and try to double click on a .cfm file, I get a dialog box..Can't Find A Valid Editor For This File Extension..
    I tried the support chat and they said Dreamweaver support was not available, try again later???
    So I thought I would reinstall the CC version and now I can see the Dreamweaver icon next to the files but still ... can't open the file..
    Any assistance would be appreciated?
    Leo

    The issue is only in Windows 8.x where when Dreamweaver CC is installed, it is not able to turn on the file type associations by default.  The workaround for now is to manually add the extensions both within Windows and then within Dreamweaver CC itself.
    Go to Control Panel > Programs > Default Programs > Set Your Default Programs and select Dreamweaver CC and then select 'Choose defaults for this program' and Select All or the extensions you want to open in Dreamweaver CC
    Start Dreamweaver CC and go to Edit > Preferences > File Types/Editors and add '.cfm .cfc' to the extensions and then add C:\Program Files (x86)\Dreamweaver CC\Dreamweaver.exe then click on Apply and Close
    That should be it.
    James

  • Excel cannot open the file beacuse the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file [help]

    Hi,
    I have a excel file that I have been using since beginning of year.
    Yesterday, I tried to open it but a message comes out "
    Excel cannot open the file beacuse the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file"
    After I click yes, the page is blank. The file is about 400kb in size.
    I have try open and repair and third party repair program and not working also.
    I would appreciate a lot if you can help me.
    Thank you very much.

    Per your post, this problem might be caused by malware on the affected machine.
    http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2013/09/07/quot-cannot-open-the-file-because-the-file-format-or-extension-is-invalid-quot-opening-office-files.aspx
    In order to clean your machine, run Microsoft Safety Scanner (http://www.microsoft.com/security/scanner/en-us/default.aspx) to kill the malware, and then repair Excel file itself.
    If this is not the case, feel free to post back and let me know. Thanks.
    Tony Chen
    TechNet Community Support
    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.

  • DW CC: Can't find a valid editor for this file extension

    Hi,
    I am using dreamweaver cc for 1 month now. I have been having difficulty opening .asp file.
    In the File panel, when i click on one of the asp files, the error message is 'Can't find a valid editor for this file extension'.
    To solve this problem, I will right click on the file and choose Open with > Dreamweaver.
    However, this is very inconvenient. Someone pls help!

    You can configure that in your Operating System.  In my version of Windows XP, open any folder and  select TOOLS/FOLDER OPTIONS/FILE TYPES then scroll to the asp file type and select DW as the editor.

  • Can't find a valid editor for this file extension

    When I try to open access from within Dreamweaver I get this
    error message.
    Can't find a valid extension for this file extension
    I have MSACCESS showing in Edit > Preferences > File
    Types Editors
    Many Thanks for any help
    John

    Support for ColdFusion and other databases were removed from DWCC. You can add them back with the Legacy Extension, or adding a paid extension from DMX Zone...
    About 1/2 way down this page for the legacy extension: http://blogs.adobe.com/dreamweaver/
    It's a paid extension, but adds back a lot of the things that were removed...
    http://www.dmxzone.com/go/22072/dmxzone-database-connector-php

  • Need help " Can't find a valid editor for this file extension" not sure why I am getting and this or what to do.

    also say explorer not reading SWF files and I have to reload them? Not sure what that is either,
    Thanks
    Jim

    Hi Nancy
    Trying to update my site got to make some changes.  Do you work on sites via remote? I am on Cloud.
    : Nancy O. 
    Sent: Monday, September 01, 2014 3:47 PM
    To: James Neidner
    Subject:  Need help " Can't find a valid editor for this file extension" not sure why I am getting and this or what to do.
    Need help " Can't find a valid editor for this file extension" not sure why I am getting and this or what to do.
    created by Nancy O. <https://forums.adobe.com/people/Nancy+O.>  in Dreamweaver support forum - View the full discussion <https://forums.adobe.com/message/6692200#6692200>

  • Add Valid (not Default) File Extensions

    I sometimes want to open source code files in Pages, but the file extensions are grayed out (eg foo.c, foo.cpp, foo.rb, foo.haml.html, foo.css). (I usually do this to print out nicely formatted code snippets for meetings)
    Of course I could make Pages the default program to open such files, but I'd much prefer to leave 'vim' as the default! What I'd like is to not have to rename the 'foo.haml.html' files to 'foo.txt' in order to get Pages to admit that it can open them. In other words, to add a dozen additional plain-text file extensions to the ones that Pages is willing to treat as plain text.
    - Randy

    If you change the extension name, you will just get an unusable file.
    If I give trousers to my daughter I will not get a second son
    The only acceptable changes are:
    replace .pages by .template to get … you win, you will get a template
    replace .pages by .zip to be able to expand the packed file if the document was a flatFile one.
    Only Pages may read Pages document.
    I replaced .pages by .piges just for see.
    I got the alert claiming that there is no defined application to open file with such extension.
    I was able to use the Get Info path to teach Pages to open this document but I didn't. No need to store garbage in the launchServices database.
    Yvan KOENIG (VALLAURIS, France) mercredi 28 juillet 2010 23:15:43

  • Why does the "open with" function often not recognize valid file extensions

    Sample situation: I often need to open JPGs downloaded from the Internet in Photoshop, but I need to keep the default program as Preview.
    When I attempt to open the image in PS using the "Open With" function (in the Edit menu), there are often no choices - it's blank, so I need to open it in preview and then save it as a PSD file to quickly open in PS. Other times I will get a list of other installed programs like Excel, and need to scroll down to the "open with another program" button, where I need to manually find the PS application. Of course, I can always open the file from within PS, but why is the Apple option so seemingly arbitrary from one similar file to the next?
    There is often no rhyme or reason for the programs it offers me.
    This happens with other file extensions, too.
    Is this a known bug?

    It's up to the applications to declare what types of files they can open. They do so by storing the information in the CFBundleDocumentTypes section of the Info.plist file in the application's .app directory. If you know what you are doing, you can edit the plist file to add your own file types/extensions. Unfortunately, I don't know of a good application to do that for you (but it's not a bad idea for one, if I get the time).

  • Wrong File Extension after using "Save AS" in PS7 and PSCS

    After using 'Save As' the file extension is incorrect (such as filename.psd.jpg) or on opening an image file saved with Save As Photoshop returns the message "Could not complete your request because it is not a valid Photoshop Document".
    There's a setting in 'Tweak UI' under the heading 'Common Dialogs' that offers a choice of disabling 'Enable AutoComplete'.
    If you disable 'Enable AutoComplete' then Photoshop 7 and 8 (CS) will no longer add the appropriate ending to a file when using 'save as'.
    Unfortunately re-enabling this option does NOT appear to cure the problem, and a re-install of the O/S may be necessary.
    (Courtesy of Russell Proulx)

    That would work if I scanned each card one at a time but that would increase my scanning time 9X.
    Here's a sample of my scanned image:

  • Embedded Windows Media PLayer With Non-Standard File Extension

    I have embedded a windows media player in a asp.net web page, using the usual
    <object> and <embed> tags. The video is served by an ashx (http handler). When I try to play the video, I usually (but not always) get an error message telling me that the file extension (ashx) does not match the file format.
    This happens in IE (8, 9, 10, 11) and also in Firefox (latest) with the WMP plugin.
    I know that the tags (with classid, etc) are correct because the media player displays and allows me to click the 'play' button.
    The ashx returns the correct mime type (video/x-ms-wmv) and a valid file name (somevideo.wmv) in the response headers. I have tried content-disposition attachment and inline.
    I have tried urls using 'http://', 'https://', and '//' (which I prefer)
    If I put the url (including the .ashx) of the video file in the browser address bar directly, the video downloads and plays in the standalone media player.
    If I modify the object tag to use a direct path to the video file (/somewhere/somevideo.wmv), it works - but I can't use this as a solution.
    The same ashx serves up video and audio in various other formats with out any fuss - it just seems that the embedded windows media player doesn't like it.
    This has been working for several years - I think this is some new behavior, though I can't identify what has changed, other than browser updates.
    Any ideas on what could be causing this? Am I missing something simple?

    Hi,
    Tools>Internet Options>Security tab, click "Reset all zones to default"
    Advanced tab of Internet Options>uncheck "Do not save encrypted files to disk"
    f12>Networking tab, click the Start button, navigate to your page and observer the response header and content.
    To determine if you page is being rendered in a x64 host (all IE versions and WaterFox, type
    navigator.platform in the IE Developer tools Console tab,
    Post questions about html, css and scripting for website development using MSIE browsers to the IE Web Development forum... WITH a link to your website.
    Rob^_^

  • [JS] Need Help Removing File extension (in CS2 and CS3)

    Hello All.
    I have a menu in a dialog that needs to list some file names, but without their file extensions (which will always be .txt in my case). The following is some code that successfully does this in CS3, but I also need it to work in CS2. Do you have any other ways to do this? One code that works in both versions (CS2 and CS3) is ideal.
    myNameWithoutExtensionFunction = function( myNameWithExtention ) {
    myNameWithoutExtension = myNameWithExtention
    myEndOfFileName = myNameWithoutExtension.lastIndexOf( "." )   // get the last period (.) in the filename
    if ( myEndOfFileName > -1 ) {
      myNameWithoutExtension = myNameWithoutExtension.substr( 0, myEndOfFileName )
    return myNameWithoutExtension
    Thanks in advance.
    Dan

    I realized my mistake. The above code works just fine in CS2. My mistake was elsewhere. The name I was sending to this function wasn't being recognized by CS2. Once I corrected that and sent a valid name to this function it worked. So in case someone needs to remove file extensions, feel free to use the above function!

  • Need the file extensions database table name

    Hi,
    I need to know the Database table name for file extensions in WCC.
    Please check the image for reference .

    Hi 2790552
    Please look at file doc_config.htm in the location <middleware_home>/Oracle_ECM1/ucm/idc/resources/core/tables/doc_config.htm
    This is the file which helps in building the applet view.
    I do belive that revisions and documents table might be used for validation and other specific things, but thats more in the context of document processing and from component IBR at runtime. But administration sake, i thing it works from the these config files since database doesn't have any table to hold this info.

  • Can't get DW to recognize new file extensions

    I'm trying to get DW to recognize the following file
    extensions as HTML: .pt, .zpt, and no extension.
    I tried to follow the instructions in the article "Changing
    and adding file extensions recognized by Dreamweaver MX": I entered
    the two extensions in all caps in the :All documents and :HTML
    documents lists in Extensions.txt. And (just as a guess) I tried
    entering two successive commas, hoping they would be interpreted as
    "no extension".
    None of these tricks has enabled me to open any of the files
    from the "Files" list in DW. I just get "Can't find a valid editor
    for this file extension."

    Thanks, Alan. I was indeed editing the wrong Extensions.txt.
    Editing the one under "\Documents and Settings" rather than the one
    under "\Program Files" did the trick (I'm running Windows XP).
    Hope springs eternal, so let me pursue the question about
    extensionless files one step more. I'm trying to use DW as the
    editor for developing a Plone site. Plone's basic HTML files are
    extensionless, and I fear it would screw up the links within Plone
    if I added extensions to these file names. However: Within Plone, I
    can designate DW as my external editor, and then (by clicking on an
    icon in the Zope Management Interface that underlies Plone) open
    the extensionless Plone files in DW (tho only in code view). How
    come DW will open a file that was tossed over from Plone, but it
    won't open the same file from its own "Files" list?

  • What is going on here? .txt file extension

    I apologize for asking this question, but at the risk of sounding completely fried, here goes...
    I've saved my program in Notepad with the .java file extension, but when I run dir command in DOS, the file ends with the .txt file extension (i.e. HelloWorld.java.txt). Could someone give me a clue how to keep Notepad from automatically ending my program with this .txt file extension.? I've have not encountered this problem before.
    Thanks

    Thanks for your help.
    I figured out that I didn't have the .java file extension defined in Windows. Because Notepad didn't recognize .java as a valid file type, it would automatically assign the .txt after my program files.
    To fix this...
    1.) Start Explorer
    2.) Select the View...Options... file menu
    3.) Click on the File Types tab
    4.) Click on the New Type... button
    5.) Enter the following in the Description of type: edit box: Java Files
    6.) Enter the following in the Associated extension edit box: .java
    7.) Click OK
    8.) Click OK
    Thanks for your responses.
    CJ

  • Xht file extension still requires manual configuration

    to open the files with an xht extension with the File Panel, i needed to configure the following file:
    /Users/me/Library/Application\ Support/Adobe/Dreamweaver\ CS5/en_US/Configuration/Extensions.txt
    adding XHT after XHTML on the line for HTML documents enables Dr CS5 to open a file with an xht extension via the Files Panel.
    maybe a future update will already include the xht extension as an HTML type of document.

    Hi Ron,
    as far as i know with regard to xht as a web standard, the xht file extension is used the same as the xhtml file extension (which is also my understanding for the use of htm and html).
    w3c has a specific validator for XHTML 1.1 documents. there is a link from pages on my web site at http://www.enhanceability.com/0.xht (near bottom of the page).
    i don't know how widespread support is for xht as XHTML (HTML) among the various browsers and apps and networks, however I can browse such pages with near lightning speed with Safari, Firefox, and some other browsers.
    i just noticed that although Safari 5.0 renders an XHTML page with an xht file extension, when I try to save the page as page source it enforces the xhtml file extension, without allowing the xht file extension. (however i can rename with xht in the finder)
    as far as Adobe Dreamweaver CS5, it seems that i needed to configure two files so that the FilesPanel could open a doc with an xht file extension, and also so that the code view of a document with an xht file extension also showed code highlighting.
    Applications/Adobe Dreamweaver CS5/Configuration/DocumentTypes/MMDocumentTypes.xml
    and
    MyUser/Library/ApplicationSupport/Adobe/Dreamweaver CS5/en_US/Configuration/Extensions.txt
    it was simple to add XHT after XHTML in the HTML documents lists, yet there must be a better way.
    Yes, I am familiar with XHTML. I followed the link that you provided to here:
    http://www.enhanceability.com/dev/0.xht
    Which has a link to this page:
    http://www.w3.org/MarkUp/2008/ED-xhtmlmime-20080618/
    I think you have misinterpretted that information. I do not see anywhere on the W3C page that recommends using .xhtml or .xht file extensions.
    I also found this FAQ that explains my understanding about XHTML documents:
    http://www.webheadstart.org/xhtml/faq/index.html
    Yes, it would be nice to have a UI to make adding file extensions to DW easier.
    Regards,
    Randy

Maybe you are looking for

  • Two monitors in the MAC OS X Lion

    How do I make when changing the desktop on the first screen, the desktop has not changed on the second monitor? On the second monitor I have an open trading system program and I want it to be always open and there has not disappeared from sight. But

  • Need help finding intro

    I've been trying to find this intro for a while.I've been told its in imovie but i cant find it.Here's the link www.youtube.com/watch?v=dznIgkR50Os,It goes from 0:01 - 0:08.If its not in imovie anyone know where i can find the image??

  • Trouble with Extreme N base station and Express station wireless

    Upgraded extreme base station with new extreme "N" base station. Currently have the extreme "N" base station connected to cable modem on 2nd floor. I have wired the house to have the demarc on the 2nd floor. I purchased the express base station to be

  • How to get pass login after reinstalling snow leopard

    I tried unsuccessfully to upgrade to maverick and got an error message stating that the Macintosh HD disk is damaged and to erase the disk and try to install again.  I did erase the Macintosh HD disk, reinstalled snow leopard because I have a mid 201

  • Midi "plug-in" missing

    Since downloading Yosemite, thus far revealed to be a mistake, I cannot play MIDI files on many but not all sites.  "plug-in missing" but there is no option to download same.  What to do?