Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error java.io.FileNotFoundException when upload image in coldfusion

Posted on 2009-05-05
10
Medium Priority
?
905 Views
Last Modified: 2013-12-24
Hello experts.
I have a problem with my upload image code.
When i'm trying to upload one image with size:2000 x 1000 i get the error:
 An exception occured while trying to write the image.
Ensure that the destination directory exists and that Coldfusion has permission to write to the given path or file. cause : java.io.FileNotFoundException:C:\Inetpub\wwwroot\test\images\Untitled-1.jpg (file can not be found from system)
..(on line destination="#thispath#/#cffile.serverFile#")...
Any help
<CFSET thispath = expandpath("./images")>
<cfif isdefined ("uploadf1") AND CGI.REQUEST_METHOD IS "POST">
    <cfif structKeyExists(form,"foto1") and len(form.foto1)>
<CFFILE action="upload" filefield="foto1" destination="#thispath#" nameconflict="MAKEUNIQUE" >
  <!--- check if is an image --->
        <cfif Lcase(file.ClientFileExt)NEQ "gif"
	      AND Lcase(file.ClientFileExt) NEQ "jpg"
          AND Lcase(file.ClientFileExt) NEQ "jpeg">
         <cffile  action="delete" file="#thispath#/#cffile.serverfile#">
         <cfset   errors = errors & "Image 1 is not an image file!<br />">
     
     <!--- check the image size --->
        <cfelseif cffile.Filesize GT 500 * 1024>
          <cffile  action="delete" file="#thispath#/#cffile.serverfile#">
          <cfset errors = errors & "Image 1 is bigger than alowed!<br />">
        <cfelse>
    
     <!--- check if there is allready img_1 then delete the file to replace it with the new one--->
          <cfif  getDBimage1.Recordcount NEQ 0>
         
           <cffile action="delete" file="#thispath#/#getDBimage1.img_Text#">
           <cffile action="delete" file="#thispath#/thumbs/#getDBimage1.img_Text#">
           <cffile action="delete" file="#thispath#/bigsize/#getDBimage1.img_Text#">
          </cfif>
     <!--- end --->
     <!--- resize the file --->
             <cfimage name="uploadedImage"
             source="#thispath#/#cffile.serverFile#" >
             <cfimage action="resize"
             height="#newHeight#"
             width="#newWidth#"
             source="#uploadedImage#"
             destination="#thispath#/#cffile.serverFile#"
             overwrite="true"/> 
     
             <cfimage action="resize"
             height="#thumbHeight#"
             width="#thumbWidth#"
             source="#uploadedImage#"
             destination="#thispath#/thumbs/#cffile.serverFile#"
             overwrite="true"/>
    
             <cfimage action="resize"
             height="#bigHeight#"
             width="#bigWidth#"
             source="#uploadedImage#"
             destination="#thispath#/bigsize/#cffile.serverFile#"
             overwrite="true"/>
             
 
    <!--- end --->
          <CFSET ServerFile1 = CFFILE.SERVERFILE>
 </cfif>
  </cfif

Open in new window

0
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24305914
is this only happened while uploading this particular image or it happened to all images
0
 
LVL 2

Author Comment

by:Panos
ID: 24306090
Hi erikTsomik:
I just tested with another image 1024 x 686 and i got again the error
0
 
LVL 2

Author Comment

by:Panos
ID: 24306136
For one image 359x359 and smaller once i have no problem.
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
LVL 27

Expert Comment

by:azadisaryev
ID: 24306173
is your C: drive running out of space, perhaps?

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 24306193
Hi azadi
I have left 4,7 gb .Is this not enough?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 1800 total points
ID: 24306213
It may also be this image resize bug

http://kb2.adobe.com/cps/403/kb403411.html
CFImage and the image functions can leave an image file locked after an initial write to disk in Adobe ColdFusion 8.0.1. This can cause subsequent operations on the image to fail with an error similar to the following:

"An exception occurred while trying to write the image. Ensure that the destination directory exists and that ColdFusion has permission to write to the given path or file. Cause: java.io.FileNotFoundException: /pathToImage/portrait.jpg"
0
 
LVL 16

Assisted Solution

by:duncancumming
duncancumming earned 200 total points
ID: 24306282
You refer to both the file and cffile scope, e.g.
file.ClientFileExt

The file scope is deprecated, and should be replaced with cffile.  That's not going to fix your problem, just a word of advice.

Secondly, you upload the file, then check the extension is gif or jpg, and delete the file if it's not.  The better way to do this might just be to use the Accept attribute on the <cffile>, e.g.
<CFFILE action="upload" filefield="foto1" destination="#thispath#" nameconflict="MAKEUNIQUE"  accept="image/gif, image/jpg, image/jpeg">
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24306314
@panosms:
>> I have left 4,7 gb .Is this not enough?

that should be enough :) ...

do check out _agx_'s suggestion about the image locking bug - that could be the culprit, even though in my previous bouts with it it has manifested itself disregarding the image filesize...

does the error occur on <cffile> operation or somewhere else? can you check the line number reported in the cf error you get and post that line of code?

Azadi
0
 
LVL 2

Author Comment

by:Panos
ID: 24306388
Ok i solve it
It was the bug fix.
Thank you
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 31578070
Thank you all for your help.
duncancumming i gave a few points for your advice too.
I would be glad if someone could helpme with the cfloop problem i have in that question :http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_24380974.html
regards
Panos
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question