Link to home
Start Free TrialLog in
Avatar of iqbalwali
iqbalwali

asked on

CFfile upload question!

Hi,

I want my site vistors to be able to upload there pictures on the server. I am using the following codes but it is not working. Can some body tell me what's wrong with it?

<!-- if form submitted -->
<cfif isdefined('Form.picture')>
<-- !find the current directary to same the picture -->
<cfset
CurrentDir=GetDirectoryFormPath(ExpandPath("*.*"))>
<cffile
action="upload"
filefield="picture"
destination="#CurrentDir#"
accept="text/html"
nameconflict="MakeUnique">
</cfif>
<!-- show the form -->
<form action="upload.cfm" method="post" enctype="multipart/form-data"></form>
Please Choose a file to upload
<br>
<input type="File" name="picture" size=40>
<br>
<input type="submit">
</form>

Thank you!
Avatar of cheekycj
cheekycj
Flag of United States of America image

what errors are you getting?

are you using this as your basic example:
http://cfhub.com/advanced/cffile/upload.cfm

try outputing file attributes after you upload:

<cfoutput>#File.FileWasSaved#,#File.ServerFileName#,#File.FileExisted#</cfoutput>

What is shown.

CJ
Avatar of iqbalwali
iqbalwali

ASKER

CJ,

It is not showing me any error. When i click the uplaod button and choose the file from other dirctory on my PC and say ok and click again on upload button to upload it, nothing will happene and no error page. It won't take me to any page it keeps me on the same form page.

That is the way the code is written.

If you want it to goto a another page.. write the code that way.

Right now.. it uploads the file and displays the form again.

If you want to change it try:

<!-- if form submitted -->
<cfif isdefined('Form.picture')>
<-- !find the current directary to same the picture -->
<cfset
CurrentDir=GetDirectoryFormPath(ExpandPath("*.*"))>
<cffile
action="upload"
filefield="picture"
destination="#CurrentDir#"
accept="text/html"
nameconflict="MakeUnique">
Upload Successful!
<cfelse>
<!-- show the form -->
<form action="upload.cfm" method="post" enctype="multipart/form-data"></form>
Please Choose a file to upload
<br>
<input type="File" name="picture" size=40>
<br>
<input type="submit">
</form></cfif>

CJ
CJ,

What I meant that it is not upload the file.  I think something is wrong with codes. My aim is to upload the file. I tried it also on the server but nothing happenend.

ASKER CERTIFIED SOLUTION
Avatar of techy6
techy6
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
good catch techy6.