Professional Web Applications Themes

image upload again - Coldfusion - Advanced Techniques

well i am using the code below, i need the name of the file uploaded to be inserted to a record in my table it works but i get the vaue of in my column instead of the file name any ideas, also if there is no image selected i get an error saying no image was selected how can i get around this? <CFFILE ACTION="UPLOAD" DESTINATION="c:\inetpub\wwwroot\CompanyImages\" FILEFIELD="WebSite_CompanyLogo" ACCEPT="image/pjpeg, image/jpeg, image/jpg, image/jpe_, image/pjpeg" nameConflict = "MakeUnique"> <CFSET myFileName = #form.WebSite_CompanyLogo#> <cfquery datasource="DPSGuide"> UPDATE Aged_Care_Facility_Details SET WebSite_CompanyLogo = '#myFileName#' WHERE ID=#ID# </CFQUERY>...

  1. #1

    Default image upload again

    well i am using the code below, i need the name of the file uploaded to be
    inserted to a record in my table

    it works but i get the vaue of in my column instead of the file name any
    ideas, also if there is no image selected i get an error saying no image was
    selected how can i get around this?


    <CFFILE ACTION="UPLOAD"
    DESTINATION="c:\inetpub\wwwroot\CompanyImages\"
    FILEFIELD="WebSite_CompanyLogo"
    ACCEPT="image/pjpeg, image/jpeg, image/jpg, image/jpe_, image/pjpeg"
    nameConflict = "MakeUnique">

    <CFSET myFileName = #form.WebSite_CompanyLogo#>

    <cfquery datasource="DPSGuide">
    UPDATE Aged_Care_Facility_Details
    SET WebSite_CompanyLogo = '#myFileName#'
    WHERE ID=#ID#
    </CFQUERY>

    Craig77 Guest

  2. #2

    Default Re: image upload again

    you would instead do:
    <cfset myFileName = #cffile.serverFile#>

    <cfquery datasource="DPSGuide">
    UPDATE Aged_Care_Facility_Details
    SET
    WebSite_CompanyLogo = <cfquery paramvalue="#myFileName#">
    WHERE ID = #ID#
    </CFQUERY>

    as for gettin an error about the image....

    <cfif #form.WebSite_CompanyLogo# eq "">
    (this would do nothing)
    <cfelse>
    run the upload code you have
    </cfif>

    weswhite7 Guest

  3. #3

    Default Re: image upload again

    ok i tried that but i get this error

    Context validation error for tag cfquery.
    The start tag must have a matching end tag. An explicit end tag can be
    provided by adding </cfquery>. If the body of the tag is empty you can use the
    shortcut <cfquery .../>.

    The error occurred in C:\CFusionMX7\wwwroot\CFIDE\DPSGuideWeb\All
    Files\WebSite\Files\Update.cfm: line 59

    57 : <CFSET myFileName = #cffile.serverfile#>
    58 :
    59 : <cfquery datasource="DPSGuide">
    60 : UPDATE Aged_Care_Facility_Details
    61 : SET WebSite_CompanyLogo = <cfquery paramvalue="#myFileName#">



    Craig77 Guest

  4. #4

    Default Re: image upload again

    can you post your whole block of code?
    weswhite7 Guest

  5. #5

    Default Re: image upload again

    ok see below

    many thanks

    <cfif #form.WebSite_CompanyLogo# eq "">
    <cfelse>

    <CFFILE ACTION="UPLOAD"
    DESTINATION="c:\inetpub\wwwroot\CompanyImages\"
    FILEFIELD="WebSite_CompanyLogo"
    ACCEPT="image/pjpeg, image/jpeg, image/jpg, image/jpe_, image/pjpeg"
    nameConflict = "MakeUnique">

    <CFSET myFileName = #cffile.serverfile#>

    <cfquery datasource="DPSGuide">
    UPDATE Aged_Care_Facility_Details
    SET WebSite_CompanyLogo = <cfquery paramvalue="#myFileName#">
    WHERE ID=#ID#
    </CFQUERY>

    </cfif>
    <CFOUTPUT>Name of file uploaded to server: #myFileName#</CFOUTPUT>

    Craig77 Guest

  6. #6

    Default Re: image upload again

    Ok see attached code..

    you need to make sure that in your form you make a hidden field to hide your
    id that has been assigned

    <input type="hidden" name="id" id="id value="#id#">

    <cfif isdefined("form.submit")>

    <cfif #form.WebSite_CompanyLogo# eq "">

    <cfelse>

    <CFFILE ACTION="UPLOAD"
    DESTINATION="c:\inetpub\wwwroot\CompanyImages\"
    FILEFIELD="WebSite_CompanyLogo"
    ACCEPT="image/pjpeg, image/jpeg, image/jpg, image/jpeg, image/pjpeg"
    nameConflict = "MakeUnique">

    <CFSET myFileName = #cffile.serverfile#>

    <cfquery datasource="DPSGuide" name="namehere" password="passwordhere"
    username="usernamehere">
    UPDATE Aged_Care_Facility_Details
    SET
    WebSite_CompanyLogo = <cfquery paramvalue="#myFileName#">
    where id = #form.id#
    </CFQUERY>

    </cfif>
    <CFOUTPUT>Name of file uploaded to server: #myFileName#</CFOUTPUT>

    </cfif>

    weswhite7 Guest

Similar Threads

  1. Upload an image
    By suburbsalliance in forum Macromedia Contribute General Discussion
    Replies: 1
    Last Post: June 13th, 06:51 AM
  2. Image Upload
    By Seth Buntin in forum Coldfusion - Advanced Techniques
    Replies: 11
    Last Post: November 28th, 01:08 AM
  3. How to upload an image in asp.net
    By Varun_789 in forum ASP.NET General
    Replies: 4
    Last Post: July 12th, 11:37 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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139