User selects image1.jpg from their computer and submits form. Name of file uploaded to server: #myFileName# UPDATE FileTable SET FileName = '#myFileName#' [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => zoeski80 [ip] => zoeski@zoeski.c [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 16 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> upload file not required - Coldfusion - Advanced Techniques

upload file not required - Coldfusion - Advanced Techniques

Gday hope you can help, think its an easy one!!!! uploading a image, at the min i get a fault from my action.cfm because there was no image selected in the upload box, is there a way not require this field? i need my form to upload but if there is no image there thats ok hope you understand...

  1. #1

    Default upload file not required

    Gday hope you can help, think its an easy one!!!!

    uploading a image, at the min i get a fault from my action.cfm because there
    was no image selected in the upload box, is there a way not require this field?
    i need my form to upload but if there is no image there thats ok

    hope you understand

    Craig77 Guest

  2. #2

    Default Re: upload file not required

    Hey Craig

    Just check for
    <CFIF Trim(Form.ImageFieldName) NEQ ''>
    UPLOAD FILE using CFFILE
    <CFELSE>
    do not do anything with the image as none was selected
    </CFIF>

    Is this what you mean?

    zoeski80 Guest

  3. #3

    Default Re: upload file not required

    hi yes many thanks

    also is it possible to state a file type, so only jpg can be uploaded?
    Craig77 Guest

  4. #4

    Default Re: upload file not required

    Use the "accept" attribute of cffile. See
    http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-p35.htm#wp3540091
    mxstu Guest

  5. #5

    Default Re: upload file not required

    ok thanks i am using

    accept="image/jpg">

    but jpg are not accepted by the server, do i need ".jpg"
    Craig77 Guest

  6. #6

    Default Re: upload file not required

    no - pretty sure it is just image/jpg

    what is happening when you send it a jpg?
    zoeski80 Guest

  7. #7

    Default Re: upload file not required

    well i get this

    The MIME type of the uploaded file "image/pjpeg" was not accepted by the server.

    but i dont know where the pjpeg comes from? its def a jpeg file i upload

    any ideas
    Craig77 Guest

  8. #8

    Default Re: upload file not required

    JPEG extensions must be different from the JPG extensions then
    this page shows the valid MIME Types for JPEG files - there a few:
    http://filext.com/detaillist.php?extdetail=JPEG

    so try adding accept="image/jpg;image/jpeg;image/pjpeg" and any others you
    want to accept and see how that goes.

    zoeski80 Guest

  9. #9

    Default Re: upload file not required

    no that still didnt work, just thinking do i have to set something in administrator?
    Craig77 Guest

  10. #10

    Default Re: upload file not required

    ok dont worry sorted many thanks

    o one more question, is there a way of putting the file name of the file uploaded into a column in my database?
    Craig77 Guest

  11. #11

    Default Re: upload file not required

    CFFILE ACTION=UPLOAD returns lots of variables about the file when it is
    complete.
    serverfile has the name of the uploaded file which you can then put into your
    database
    access as cffile.serverfile

    http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-p35.htm#wp3540091

    zoeski80 Guest

  12. #12

    Default Re: upload file not required

    ok thanks i have looked up this but i cant find any details on where to put this code?

    do i use it as an output?
    how would you set the code
    Craig77 Guest

  13. #13

    Default Re: upload file not required

    cffile.serverfile is just a variable holding the filename eg. image1.jpg


    <CFFILE ACTION=UPLOAD ...>
    <CFSET myFileName = cffile.serverfile>

    You can then use it to output to the screen
    <CFOUTPUT>#myFileName#</CFOUTPUT>

    or put into the database
    <CFIF Trim(myFileName) NEQ ''>
    <CFQUERY ...>
    INSERT INTO Files (FileID, FileName)
    VALUES (1, '#myFileName#')
    </CFQUERY>
    </CFIF>

    zoeski80 Guest

  14. #14

    Default Re: upload file not required

    so do i need to change "myfilename" is that the name of my <input type="file" name="WebSite_CompanyLogo">

    so it would be WebSite_CompanyLogo
    Craig77 Guest

  15. #15

    Default Re: upload file not required

    ok thanks i see what you mean now

    the only bit i dont get is below, i have never used cfquery to input files, i
    will look it up, can you check my code see if its ok

    <CFIF Trim(myFileName) NEQ ''>
    <CFQUERY name="putimages" datasource="DPSGuide">
    INSERT INTO Files (WebSite_CompanyLogo)
    VALUES (1, '#myFileName#')
    </CFQUERY>
    </CFIF>

    Craig77 Guest

  16. #16

    Default Re: upload file not required

    I think we have our wires crossed ...

    <!--- FORM PAGE --->

    <input type="file" name="WebSite_CompanyLogo">
    User selects image1.jpg from their computer and submits form.


    <!--- ACTION PAGE --->

    <!--- upload file to server in specified location, get file details from form
    field as specified in FILEFIELD --->
    <CFFILE ACTION="UPLOAD"
    DESTINATION="c:\inetpub\wwwroot\images\"
    FILEFIELD="WebSite_CompanyLogo"
    ACCEPT="image/jpg;image/jpeg;image/pjpeg"
    nameConflict = "MakeUnique">

    <!--- get name of file that was saved to the server, may be different from
    what
    users uploaded file was (image1.jpg) as there may have already been a file
    with this name on the server so it had to rename it etc
    if file upload was not successful this will probably be empty so may need to
    add some checking --->
    <CFSET myFileName = cffile.serverfile>

    <!--- this will output image1.jpg assuming the image name was not changed when
    uploaded
    otherwise it might be something like ACF1CA.jpg or some other auto generated
    name --->
    <CFOUTPUT>Name of file uploaded to server: #myFileName#</CFOUTPUT>

    <!--- if you want to save this filename in the database --->
    <CFQUERY ...>
    UPDATE FileTable
    SET FileName = '#myFileName#'
    </CFQUERY>

    zoeski80 Guest

  17. #17

    Default Re: upload file not required

    You're not adding the actual file into the database, you are adding the name of
    the file only. eg. image1.jpg. The file is saved on the server, you are just
    adding a reference for the filename to the database so you know which file on
    the server that database entry links to.

    So you're actaully just adding a text string to the database.

    so when you retrieve the data later you will need to know what directory it
    was stored in so you can use the IMG tag to display the image
    <IMG SRC="http:// <location of file> / #DatabaseQuery.FileNameField#">

    Your code is alright except your INSERT INTO line has one field name specified
    in the brackets but your VALEUS line has 2 values : 1 and myFieldName. Cannot
    insert 2 values into one column/field in the database.

    zoeski80 Guest

  18. #18

    Default Re: upload file not required

    ok its nearly working expect instead of the file name being inserted to the
    database i get
    C:\CFusionMX7\runtime\servers\coldfusion\SERVER-IN

    <CFIF Trim(myFileName) NEQ ''>
    <CFQUERY name="putimages" datasource="DPSGuide">
    INSERT INTO Aged_Care_Facility_Details (WebSite_CompanyLogo)
    VALUES ('#myFileName#')
    </CFQUERY>
    </CFIF>

    Craig77 Guest

Similar Threads

  1. Replies: 2
    Last Post: July 29th, 11:41 AM
  2. Upload Friendly (Multiple File Upload Applet)
    By ochiana in forum Coldfusion Server Administration
    Replies: 1
    Last Post: February 22nd, 02:16 AM
  3. Replies: 2
    Last Post: October 14th, 07:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •