Skip to main content
Known Participant
January 31, 2010
Question

CFFileUpload with inserting a record

  • January 31, 2010
  • 3 replies
  • 2785 views

Hi guys,

I'm bumping into the wall with this one. What i'm trying to do is using cffileupload tag upload multiple files, resize and rename them, and then insert into database the file name. All goes well until the last bit (insert into database). Have no clue where it goes wrong hence a call for help.

<cffileupload url="process.cfm?id=#URL.upd#" align="center" width="700" maxuploadsize = "200" progressbar = "true" bgcolor="white" oncomplete="printFileName" />

process.cfm:

<cfparam name="URL.id" default="1">
<cfquery name="get_photos" datasource="IGES">
SELECT *
FROM event_photos
WHERE event_id = <cfqueryparam value="#URL.id#" cfsqltype="cf_sql_numeric">
ORDER BY id DESC
</cfquery>

<cfset currentDirectory = #expandPath("../images/events/#URL.id#/")#>
<cfif DirectoryExists(currentDirectory)>
<cfelse>
<cfdirectory action="Create" directory="#expandPath("../images/events/#URL.id#/")#" mode="777">
</cfif>

<cffile 
    action = "upload"
    destination = "#expandpath('../images/events/#URL.id#/')#"
    nameconflict="makeunique"
    >
   
<cfimage action="resize"
width="640"
height="480"
source="#expandpath("../images/events/#URL.id#/#file.serverfile#")#"
destination="#expandpath("../images/events/#URL.id#/#file.serverfile#")#"
overwrite="yes">
   
<cffile action = "rename"
   source="#expandpath("../images/events/#URL.id#/#file.serverfile#")#"
destination="#expandpath("../images/events/#URL.id#/5.jpg")#">
   
<cfquery name="newrecord" datasource="iges" >  
    INSERT INTO event_photos (photo)
VALUES ("3")
</cfquery>

What happens is it uploads the file, resizes it, renames it and then gives me "status code = 50" error. What am I doing wrong? photo field in database is integer.

cheers,

Simon

    This topic has been closed for replies.

    3 replies

    Inspiring
    January 31, 2010
    [...] and then insert into database the file name.

    [...]

       
    <cfquery name="newrecord" datasource="iges" >  
        INSERT INTO event_photos (photo)
    VALUES ("3")
    </cfquery>


    That's not inserting a file name, either.  It's inserting a 3.  And you should be using single-quotes in an SQL statement, not double-quotes.  Or if it's a numeric type column, no quoted at all.

    --

    Adam

    Simon.DauAuthor
    Known Participant
    January 31, 2010

    Hi Cameron,

    I suppose to insert an event id and photo name. it's just one of the attempts (with the 3). sorry for confusion. Anyway. What I have discovered so far is absolutely hard to explain, as today couple of times it actually went through and inserted the record.

    It seems that for some reason it doesn't want to execute any sort of query. The query at the beginning doesn't produce any results either. (though time to time it works). I just found out that in order to pass to parameters via url you have to enclose it like this :

    <cfset request.theURLVars = urlEncodedFormat("a=1&b=2&c=3") />

    otherwise flash cuts out everything after first parameter. Maybe it's something related?

    anyway, so far I'm clueless and seeking (shouting) for help as it drives me mad!

    Inspiring
    January 31, 2010

    How did flash get into this?  All your questions have referred to cfml tags.  Your opening post referred to process.cfm.

    It's clear that you are requesting assistance, but your requests are not clear.

    Inspiring
    January 31, 2010

    What happens is it uploads the file, resizes it, renames it and then gives me "status code = 50" error. What am I doing wrong? photo field in database is integer.

    Status code 50, or 500?  I imagine it's a 500.

    I would expect an entry to go into the server's exception log when this happens, detailing what exactly went wrong.  What does it say?

    --

    Adam

    Inspiring
    January 31, 2010

    The quotes around the numbers are messing you up.

    Simon.DauAuthor
    Known Participant
    January 31, 2010

    Cheers Dan for your quick response but I've tried all of the possible combinations. Nothing worked as yet.