views:

291

answers:

3

I'm posting a form in Coldfusion on Linux. Form has a file field. CF requires the enctype="multipart/form-data" attribute on the form tag. If I have this, I get a "JRun Servlet Error - 500 No such file or directory"

If I take the attrib out, the form posts and I get the CF "enctype=multipart/form-data" error.

What to do?

Here's a stripped version of the form:

 <form action="post.cfm" name="form2" id="port_form" method="post" enctype="multipart/form-data">
      <input type="text" id="name" name="name" value="#port_name#"><br>
      <input type="file" id="before" name="before"><br>
      <input type="hidden" name="port_id" value="#port_id#" />
      <button type="submit" name="post"> Post Portfolio Item </button>  
 </form>

Here's the page i'm posting to (post.cfm)

 <cfif form.before neq "">
    <cfinvoke component = "#application.cfcPath#.file" method = "upload" returnVariable = "beforeFile" theField="before">
 <cfelse>
    <cfset beforeFile = ''>
 </cfif>

 <cfif form.after neq "">
    <cfinvoke component = "#application.cfcPath#.file" method = "upload" returnVariable = "afterFile" theField="after">
 <cfelse>
    <cfset afterFile = ''>
 </cfif>    

 <cfinvoke component = "#application.cfcPath#.portfolio" method = "post" beforeFile="#beforeFile#" afterFile="#afterFile#">

 <cfif form.port_id eq 0>
    <cfset message = "The Portfolio Item has been successfully inserted.">
 <cfelse>
    <cfset message = "The Portfolio Item has been successfully updated.">
 </cfif>

 <cf_forward fuseaction="#fusebox.circuit#.home" message="#message#">
A: 

You've probably already tried this, but have you tried all upper-case or all lowercase in your paths and file names? Sometimes CF will mangle the upper/lower case thing.

anopres
I have matched case exactly, I don't think this is the problem because if I remove the enctype, it posts, but I get the error "CF requires enctype..." If the enctype attrib is there, it tries to find the page, but returns the 500 error.
Gene R
Have you tried uploading a very small file? I know there are some issues with very large files being uploaded.
anopres
Yea, the file i'm testing with is a 4b .txt
Gene R
+1  A: 

Possible reason is that server can not find the uploaded temp file.

Have you tried to make upload without component wrapper?

Simply

<cfif StructKeyExists(Form, "before") AND Form.before NEQ "">
<cffile
    action="upload"
    filefield="before"
    destination="#AbsPathToStoreFile#"
    >
</cfif>

<cfdump var="#cffile#">

If this fails maybe you'll be able to see more details.

Sergii
great minds think alike :-)
Adam
Oh, sorry, that's in the CFC i'm cfinvoking at the beginning of the post.cfm page. I'm using cffile and the destination is a path i've specified. But that still could have writing issues, i'll double check that...
Gene R
Nope, that wasn't it. I reduced the post.cfm file to simply "This is a test" No code, just text. Still with the 500 error, so it isn't even "finding" this file. I still think its a problem with enctype on Linux specifically?
Gene R
Enctype is protocol standart, not just CF feature. If you do not enter it, file wont be even transferred. Which user runs CF server. It is weird, but maybe this user has no access to write into /tmp/ ? I mean that prob can be BEFORE trying to move your file to dest path.
Sergii
My host is GoDaddy, shared server, so I don't have access to anything outside my webroot. CFFILE writes to a /tmp/ folder as well as a destination folder I specify? Is there a way around that? If so, I guess i'm screwed?
Gene R
Oh, in this situation the best way is contacting support. If this _is_ server misconfiguration, they are to fix it. Or at least look into logs and try to give more info.
Sergii
I've emailed them, so far, they're not too helpful via email, i'll try calling next. Thanks for all the help everyone.
Gene R
A: 

I'm wondering if the temp folder that CF is trying to save the file to is either inaccessible (permissions) or not configured properly.

You should try using the CFFILE tag and specify a folder you have access to.

Adam