Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading using variables

Status
Not open for further replies.

izachar

Technical User
Oct 7, 2000
84
CA
I am trying to upload a file to the server but I want to change the name of the file to the value of a variable. This is my code but I am getting an error when the file gets uploaded with a wrong FILEFIELD. Please help.

Code:
<b>Loader.cfm</b>
<!--- brings value of movie from main form --->
<cfset m_id=#new_mid#>

<cfoutput>
<FORM ACTION=&quot;FileUpload.cfm?m_id=#m_id#&quot;
ENCTYPE=&quot;multipart/form-data&quot;
METHOD=&quot;Post&quot;>
<PRE>

File: <INPUT NAME=&quot;FileContents&quot; TYPE=&quot;file&quot;>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;Upload File&quot;>
</PRE>
</FORM>
</cfoutput>

<b>FileUload.cfm</b>
<cfset m_id=#m_id#>
<cfset FileContents='#m_id#.jpg'>

<cfoutput>
<CFFILE
ACTION=&quot;Upload&quot;
FILEFIELD=&quot;#FileContents#&quot;
DESTINATION=&quot;C:\temp&quot;
NAMECONFLICT=&quot;MAKEUNIQUE&quot;>
</cfoutput>
 
Hey izachar,

You'll want to change this line

FILEFIELD=&quot;#FileContents#&quot;
to
FILEFIELD=&quot;FileContents&quot;

You have to pass it the name of the field and not the actual variable. This will allow the file to be uploaded correctly. You can then use <cffile> to rename it as follows:

<cffile
action=&quot;rename&quot;
source=#cffile.serverFile#
destination=&quot;....\myDirectoryPath\#m_id#.jpg&quot;
>

Hope this helps,
GJ
 
It worked thank you. In another module I am allowing the user to edit their entry but if they can modify text information and see the image that is associated with the record. If they decide not to change the image when they press the update I am getting:


Error processing CFFILE

No data was received in the uploaded file '\' Saving empty (zero-length) files is prohibited. Please make sure you specified the correct file.

I am trying to put a conditional before the cffile tag but it is not accepting it (<cfif not isdefined(&quot;FileContents&quot;)eq &quot;&quot;> I tried &quot;'\'&quot; with is like and equal but it ignores it.
 
I'm going off memory here but I believe the way you check to see if a file was sent is like this:

<cfif FileContents neq &quot;&quot;>

Let me know if this doesn't work.
GJ
 
Thank you very much your memory served you right
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top