Skip to main content
Known Participant
Jan 31, 2010 12:42 AM UTC
Question

CFFileUpload with inserting a record

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 is closed to new replies. Start a new post to keep the conversation going.

    10 replies

    Inspiring
    Jan 31, 2010 7:13 PM UTC
    [...] 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

    Translate
    Simon.DauAuthor
    Known Participant
    Jan 31, 2010 8:42 PM UTC

    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!

    Translate
    Inspiring
    Jan 31, 2010 9:50 PM UTC

    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.

    Translate
    Inspiring
    Jan 31, 2010 7:11 PM UTC

    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

    Translate
    Inspiring
    Jan 31, 2010 1:44 PM UTC

    The quotes around the numbers are messing you up.

    Translate
    Simon.DauAuthor
    Known Participant
    Jan 31, 2010 3:15 PM UTC

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

    Translate