?
Solved

Trouble with file upload

Posted on 2010-01-13
9
Medium Priority
?
264 Views
Last Modified: 2013-12-24
I have some code to upload an image to a server, and the problem is that the file is uploaded to the server with no extension, and then I can't read it from the server to move/rename it. Is it not possible to force/specify the file name by doing something like this?

   <cffile action="upload"
   filefield="imagelink"
   destination="#MediaPath#/#photoname#.jpg"
   nameconflict="makeunique"
   file="#photoname#.jpg"
  >

Why won't this work?  I've pulled "working" code from other sites and I'm still having this issue. I can see the file written to the server so I have access.
0
Comment
Question by:nonesuch
  • 4
  • 4
9 Comments
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 600 total points
ID: 26303969
remove file="#photoname#.jpg" from your code and it should work (i.e. force the the file to be saved with the filename you specify).

are you sure about not being able to access an uploaded file without extension? i do not recall that being a problem... what's your code for moving/renaming the uploaded file? you are using #cffile.serverfile# to get the uploaded filename, right?

Azadi
0
 
LVL 53

Expert Comment

by:_agx_
ID: 26304839
> i do not recall that being a problem.

Neither do I.  

On a side note, are you confirming the file is an image first (and what type)?  Forcing the file to _always_ be saved as a ".jpg" could lead to some problems down the road. For example: saving a .GIF or Word .DOC as .jpg ....
0
 
LVL 3

Author Comment

by:nonesuch
ID: 26304891
Definitely the file is an image.  I was trying to force it to .jpg just to try to get it to work and upload as an image.  It's interestingly enough saving the file name with the name of the lowest directory path -- i.e., in an example full path destination of /photos/user1/thumbnails, it is saving each copy of the image as "thumbnails1", "thumbnails2", etc. (with no extension).

 I will try out the suggestions and get back to you.  
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 3

Author Comment

by:nonesuch
ID: 26310584
Okay, so when I try to do this:

   <cffile action="upload"
   filefield="imagelink"
   destination="#MediaPath#/#photoname#.jpg"
   nameconflict="makeunique"
  >
   
   <cfdump var="#cffile#">

-----------------

results in:


struct
ATTEMPTEDSERVERFILE       1263436352.jpg
CLIENTDIRECTORY       200800708mom_0283_med.jpg
CLIENTFILE       200800708mom_0283_med.jpg
CLIENTFILEEXT       jpg
CLIENTFILENAME       200800708mom_0283_med
CONTENTSUBTYPE       jpeg
CONTENTTYPE       image
DATELASTACCESSED       {d '1969-12-31'}
FILEEXISTED       NO
FILESIZE       0
FILEWASAPPENDED       NO
FILEWASOVERWRITTEN       NO
FILEWASRENAMED       NO
FILEWASSAVED       NO
OLDFILESIZE       0
SERVERDIRECTORY       e:\websites\localuser\1\fullsize
SERVERFILE       1263436352.jpg
SERVERFILEEXT       jpg
SERVERFILENAME       1263436352
TIMECREATED       {ts '1969-12-31 19:00:00'}
TIMELASTMODIFIED       {ts '1969-12-31 19:00:00'}

------- and sure enough the image is not stored out on the server

So I modified to the other way I've tried to run it, specifying the folder and not the destination file:

   <cffile action="upload"
   filefield="imagelink"
   destination="#MediaPath#"
   nameconflict="makeunique"
  >
             
   <!--- read the image ---->
   <cfimage name="uploadedImage" source="#cffile.serverdirectory#/#cffile.serverFile#" >
   
----- and a file IS uploaded to the server, "fullsize17" without the extension,
and i get an error on <cfimage>

The e:\websites\localuser\1/fullsize17 image format is not supported on this operating system. Use GetReadableImageFormats() and GetWriteableImageFormats() to see which image formats are supported.
The error occurred on line 55.
0
 
LVL 53

Accepted Solution

by:
_agx_ earned 1400 total points
ID: 26310660
> then I can't read it from the server to move/rename it.

I think Azadi asked about this before: what code are you using to try and move/delete the file?  And what happens (full error message, etc)... ?

> and a file IS uploaded to the server, "fullsize17" without the extension

    Can you post the cfdump ?

>> and sure enough the image is not stored out on the server
>> FILEWASSAVED       NO

    Well, at least CFFILE is reporting the correct results (ie not saved)

> and i get an error on <cfimage>

     Yes, cfimage _requires_ a file extension. A work-around is to read it into a variable first. But that
     still doesn't solve the original problem.


0
 
LVL 3

Author Comment

by:nonesuch
ID: 26310707
I'm showing you all the code there is -- <cffile> to upload the file, then a <cfimage> to read the image information.  It didn't show the previous cfdump because the error overrode it. I added a <cfexit> right before the <cfimage> to show you the results now after <cffile> without specifying the image name:


struct
ATTEMPTEDSERVERFILE       fullsize
CLIENTDIRECTORY       mi1.jpg
CLIENTFILE       mi1.jpg
CLIENTFILEEXT       jpg
CLIENTFILENAME       mi1
CONTENTSUBTYPE       jpeg
CONTENTTYPE       image
DATELASTACCESSED       {d '2010-01-13'}
FILEEXISTED       YES
FILESIZE       67977
FILEWASAPPENDED       NO
FILEWASOVERWRITTEN       NO
FILEWASRENAMED       YES
FILEWASSAVED       YES
OLDFILESIZE       67977
SERVERDIRECTORY       e:\websites\localuser\1
SERVERFILE       fullsize18
SERVERFILEEXT       [empty string]
SERVERFILENAME       fullsize18
TIMECREATED       {ts '2010-01-13 22:12:43'}
TIMELASTMODIFIED       {ts '2010-01-13 22:12:43'}
0
 
LVL 3

Author Comment

by:nonesuch
ID: 26310782
hold the presses... I think I just found the culprit, and wow is it stupid.  

I was stripping off some information in the code I sent to mask some site particulars, and the fact is that the server directory really didn't have the "last directory" that I indicated, it didn't exist. So that's why it was erroring out.  Now I'm uploading just fine. Wow, that's a couple of days wasted on not completely confirming my destination directory!  Thanks for the assistance, I will award points for your patience.
0
 
LVL 53

Expert Comment

by:_agx_
ID: 26310790
What is the code used to set the value of #MediaPath#
0
 
LVL 53

Expert Comment

by:_agx_
ID: 26310792
@nonesuch,

Good, I was just about to tell you I just tested the code and ... unfortunately, it worked fine for me. So I'm glad you solved it.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

621 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