Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

File upload Issue

New Here ,
Dec 17, 2009 Dec 17, 2009

While uploading file with file name having maximum length

ex:- 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.jpg

using coldfusion, uploaded file in server gets corrupted

I am using cf8 and windows xp

code set is given below

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

<form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="img">
    <input type="submit" name="submit" value="submit">
</form

<cfif ISDefined('Form.img')>
    <cffile
        action="upload"
        destination="D:\thumb"
        filefield="img"
        nameconflict="makeunique"/>

    <cfdump var="#cffile#">
   
    <cfdump var="#len(cffile.CLIENTFILE)#">
</cfif>
------------------------------------------------------------------------

Please help?

1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 17, 2009 Dec 17, 2009

The file gets corrupted, or you have a problem with the nfile path being too long?

On Windows the restriction is on the entire file path, not simply the file name.  The file path cannot be more than 260 chars (incl. drive letter and colon and all the slashes).  The dir can be a max of... ooh... I think it's 255 chars.

So ber in mind when you upload this file to the server, the file needs to be put in a directory.  If the file name and the directory if goes in to will be longer than 260 chars, the web server is going to have to do something about that (which could be error, or it could be to truncate the file name, dunno).

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 17, 2009 Dec 17, 2009


Hi Adam,

Is there any work around for this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 17, 2009 Dec 17, 2009

Work aorund for a limitation of the Windows file system?  No.  Well: you could port to *nix I guess 😉

But you didn't answer my question.  You said it's corrupting the file.  I find this hard to believe.  I've not experimented with this, but I suspect all that's going on is that it's altering the file name.  And it's not a corruption, it's just an adjustment so that it's actually possible to save the file.

Can you please clarify exactly what the problem is you're seeing?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 17, 2009 Dec 17, 2009

Actually the file is uploaded successfully.

But the file cannot be opened.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 17, 2009 Dec 17, 2009

sujeeshdl wrote:

Actually the file is uploaded successfully.

But the file cannot be opened.

Your definition of success and my definition of success are at odds then, I think. 😉

However I know what you mean.  Somehow it is possible for CF to write to illegally-long paths, which gives the impression that the file write / relocate was "successful", but as you see: it is not.  If the file is inaccessible, it's upload is not really a "success" is it?

As I alluded to, you will need to check that the the total path length is not greater than 260chars.  And if it is, alter the path accordingly (probably by just renaming the file).

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 17, 2009 Dec 17, 2009

Adam

Path length caused the issue.

Thanks for ur suggession.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 17, 2009 Dec 17, 2009

Hi Adam,

i am not getting the full path from the input field using javascript.

Is it possible to get the full path from the input field. so that i can give a validation for the path length.

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 17, 2009 Dec 17, 2009

Hi Sujeesh,

You can retrieve the path like this,

document.getElementById("your_file_control_name").value
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2009 Dec 18, 2009
LATEST

i am not getting the full path from the input field using javascript.

Is it possible to get the full path from the input field. so that i can give a validation for the path length.

Thanks

You shouldn't need the full path on the client end, as the path on the clienty is not relevant, it's the path on the server that's relevant.  Equally, you don't need to get this on the client side at all, you only need to worry about it when the file hits the server.  Everything you should need can be handled with the form scope and <cffile action="upload"> on the form's action template.

--
Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources