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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

upload to a specific location

Status
Not open for further replies.

izachar

Technical User
Oct 7, 2000
84
CA
I have 2 sections to the application an admin and a live section. I am allowing a user to upload a file in the admin tool that has to be placed in the live section. I tried to use the relative path but it is ignoring the destination tag?

<CFSET thisPath= ExpandPath(&quot;*.*&quot;)>
<CFSET imgDirectory= GetDirectoryFromPath(thisPath)>

<CFIF IsDefined(&quot;FORM.list&quot;) AND list NEQ &quot;&quot;>
<CFTRY>
<!--- Upoad File --->
<CFFILE ACTION=&quot;UPLOAD&quot;
FILEFIELD=&quot;FORM.list&quot;
DESTINATION=&quot;#imgDirectory#&quot;
NAMECONFLICT=&quot;Overwrite&quot;>

<!--- Rename Img --->
<CFFILE ACTION=&quot;RENAME&quot;
SOURCE=&quot;#CFFILE.ServerDirectory#\#CFFILE.ServerFile#&quot;
DESTINATION=&quot;..\..\live\one\two\list.#CFFILE.ServerFileExt#&quot;>


<!--- Catch error, if it's not a txt file --->
<CFCATCH TYPE=&quot;Any&quot;>
I'm sorry, you must upload the list array file.
</CFCATCH>
</CFTRY>
</CFIF>
 
Working with CFFILE you will need to specify the complete path.
 
Yes. You could do it this way:

<CFSCRIPT>
thisPath = ExpandPath(&quot;*.*&quot;);
imgDirectory1 = GetDirectoryFromPath(thisPath);
[COLOR=666666]// get the above directory 2 levels down &quot;../../&quot;[/color]
imgDirectory2 = ListDeleteAt(imgDirectory1, ListLen(imgDirectory1, &quot;\&quot;), &quot;\&quot;);
imgDirectory2 = ListDeleteAt(imgDirectory2, ListLen(imgDirectory2, &quot;\&quot;), &quot;\&quot;) & &quot;\live\one\two\&quot;;
</CFSCRIPT>

<CFIF IsDefined(&quot;FORM.list&quot;) AND list NEQ &quot;&quot;>
<CFTRY>
[COLOR=666666]<!--- Upoad File --->[/color]
<CFFILE ACTION=&quot;UPLOAD&quot;
FILEFIELD=&quot;FORM.list&quot;
DESTINATION=&quot;#VARIABLES.imgDirectory1#&quot;
NAMECONFLICT=&quot;Overwrite&quot;>


[COLOR=666666]<!--- Rename Img --->[/color]
<CFFILE ACTION=&quot;RENAME&quot;
SOURCE=&quot;#VARIABLES.imgDirectory1#\#CFFILE.ServerFile#&quot;
DESTINATION=&quot;#VARIABLES.imgDirectory2#\list.#CFFILE.ServerFileExt#&quot;>



[COLOR=666666]<!--- Catch error, if it's not a txt file --->[/color]
<CFCATCH TYPE=&quot;Any&quot;>
I'm sorry, you must upload the list array file.
</CFCATCH>
</CFTRY>
</CFIF> - tleish
 
It seems as if it is not moving it yet. The file ends up in the folder where my admin code is executed from. Apart from the directory names is there anyhting else I need to add or change.
 
The problem may be that the code runs faster than the file is uploaded, so it's not even uploaded before the script tries to rename it. When working with files, it's good practice to use <CFLOCK>, and in this case it should only allow one <CFFILE> tag to run at a time. This should force the <CFFILE ACTION=&quot;RENAME&quot; ...> to wait until the <CFFILE ACTION=&quot;UPLOAD&quot; ...> is completed.

Try it out and let me know what happens

<CFSCRIPT>
thisPath = ExpandPath(&quot;*.*&quot;);
imgDirectory1 = GetDirectoryFromPath(thisPath);
[COLOR=666666]// get the above directory 2 levels down &quot;../../&quot;[/color]
imgDirectory2 = ListDeleteAt(imgDirectory1, ListLen(imgDirectory1, &quot;\&quot;), &quot;\&quot;);
imgDirectory2 = ListDeleteAt(imgDirectory2, ListLen(imgDirectory2, &quot;\&quot;), &quot;\&quot;) & &quot;\live\one\two\&quot;;
</CFSCRIPT>

<CFIF IsDefined(&quot;FORM.list&quot;) AND list NEQ &quot;&quot;>
<CFTRY>
[COLOR=666666]<!--- Upoad File --->[/color]
<CFLOCK NAME=&quot;#CFFILE.ServerFile#&quot;
TYPE=&quot;EXCLUSIVE&quot; TIMEOUT=&quot;30&quot;>

<CFFILE ACTION=&quot;UPLOAD&quot;
FILEFIELD=&quot;FORM.list&quot;
DESTINATION=&quot;#VARIABLES.imgDirectory1#&quot;
NAMECONFLICT=&quot;Overwrite&quot;>

</CFLOCK>

[COLOR=666666]<!--- Rename Img --->[/color]
<CFLOCK NAME=&quot;#CFFILE.ServerFile#&quot;
TYPE=&quot;EXCLUSIVE&quot; TIMEOUT=&quot;30&quot;>

<CFFILE ACTION=&quot;RENAME&quot;
SOURCE=&quot;#VARIABLES.imgDirectory1#\#CFFILE.ServerFile#&quot;
DESTINATION=&quot;#VARIABLES.imgDirectory2#\list.#CFFILE.ServerFileExt#&quot;>

</CFLOCK>

[COLOR=666666]<!--- Catch error, if it's not a txt file --->[/color]
<CFCATCH TYPE=&quot;Any&quot;>
I'm sorry, you must upload the list array file.
</CFCATCH>
</CFTRY>
</CFIF> - tleish
 
I understand what you are saying but now I don't know where the file is. It is not putting it where it did before but it is also not putting it in the right place. I search in the entire computer but the file is not there. Any suggestions ?
 
Try outputing the file names to the page so you can see what's being passed to the script:

=== START CODE EXAMPLE ===
<CFSCRIPT>
thisPath = ExpandPath(&quot;*.*&quot;);
imgDirectory1 = GetDirectoryFromPath(thisPath);
[COLOR=666666]// get the above directory 2 levels down &quot;../../&quot;[/color]
imgDirectory2 = ListDeleteAt(imgDirectory1, ListLen(imgDirectory1, &quot;\&quot;), &quot;\&quot;);
imgDirectory2 = ListDeleteAt(imgDirectory2, ListLen(imgDirectory2, &quot;\&quot;), &quot;\&quot;) & &quot;\live\one\two\&quot;;
</CFSCRIPT>

<CFIF IsDefined(&quot;FORM.list&quot;) AND list NEQ &quot;&quot;>
<CFTRY>
[COLOR=666666]<!--- Upoad File --->[/color]
<CFLOCK NAME=&quot;#FORM.list#&quot;
TYPE=&quot;EXCLUSIVE&quot; TIMEOUT=&quot;30&quot;>

<CFFILE ACTION=&quot;UPLOAD&quot;
FILEFIELD=&quot;FORM.list&quot;
DESTINATION=&quot;#VARIABLES.imgDirectory1#&quot;
NAMECONFLICT=&quot;Overwrite&quot;>

</CFLOCK>

[COLOR=666666]<!--- Rename Img --->[/color]
<CFLOCK NAME=&quot;#FORM.list#&quot;
TYPE=&quot;EXCLUSIVE&quot; TIMEOUT=&quot;30&quot;>

<CFFILE ACTION=&quot;RENAME&quot;
SOURCE=&quot;#VARIABLES.imgDirectory1#\#CFFILE.ServerFile#&quot;
DESTINATION=&quot;#VARIABLES.imgDirectory2#\list.#CFFILE.ServerFileExt#&quot;>

</CFLOCK>

[COLOR=666666]<!--- Catch error, if it's not a txt file --->[/color]
<CFCATCH TYPE=&quot;Any&quot;>
I'm sorry, you must upload the list array file.
</CFCATCH>
</CFTRY>
</CFIF>

[COLOR=666666]<!--- Output the file names --->[/color]
<CFOUTPUT>
#VARIABLES.imgDirectory1#\#CFFILE.ServerFile#[COLOR=000080]<br>[/color]
#VARIABLES.imgDirectory2#\list.#CFFILE.ServerFileExt#
</CFOUTPUT>
=== END CODE EXAMPLE === - tleish
 
Sorry to bug yo again but it is coming up with a problem in #CFFILE.ServerFile# I don't understand what it is doing so I can not troubleshoot it by myself.
 
That's my fault. The first time I sent you the code with a <CFLOCK> I used NAME=&quot;#CFFILE.ServerFile#&quot;

<CFLOCK NAME=&quot;#CFFILE.ServerFile#&quot;
TYPE=&quot;EXCLUSIVE&quot; TIMEOUT=&quot;30&quot;>


I realized that name would only work on the 2nd <CFLOCK>, but they both need to have the same name. So if you look at the most recent example of code I sent, I chnged the name of the <CFLOCKS>'s to NAME=&quot;#FORM.list#&quot;

<CFLOCK NAME=&quot;#FORM.list#&quot;
TYPE=&quot;EXCLUSIVE&quot; TIMEOUT=&quot;30&quot;>
- tleish
 
Thank you very very much it is working perfectly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top