Upload a File name with more than one spaces it's automatically convert into single space

100 Views Asked by At

I have uploaded file name as "Front page.jpg". Here there are two spaces between Front & page on my original file.

When I submit the form, The cffile.SERVERFILE comes up with Front page.jpg only single space between Front & page.

Here the file uploaded as it's original name ( double spaces between Front & page ) in my file explore but the server file return only single space between the both string.

Now, I want to pass this SERVERFILE name into my second action page & on the second action page , I should check the specific file exist or not. When I check my recent upload file( Front page.jpg ) does not exits. Because my SERVERFILE return only single space between the both string.

How I can escape from this issue.

Make sure,

  1. I have used pre tag to display the file name - It's display good with double spaces.

  2. As per client requirement I should not have a permission to rename the file with underscore( _ ) or some other delimeter to avoid space.

  3. I want to pass my file name with more than one space to another page. That's my requirement. enter image description here

My sample code here :

if( cgi.REQUEST_METHOD == "post" ) {
       tempDir = expandPath( "./temp" ) & "/";
       if( !directoryExists( tempDir ) ) directoryCreate( tempDir );

        
        fileData = fileUpload( tempDir, "fileField", "*", "makeunique" );
        writeoutput( "Display with Pre tag : <pre>#fileData.serverFile#</pre>" );
        writeoutput( "Display without Pre tag : #fileData.serverFile#" );

        writeDump( fileData );
    }
1

There are 1 best solutions below

0
accidentalcaveman On

I am not sure why, but when I tried to replicate this I also had the double spaces reduced to single spaces within the form scope.

Instead, use the getHttpRequestData method, and you should see serverfile=Front++page.jpg in the content. I have had several issues with ColdFusion manipulating http request data, but getHttpRequestData has always worked as expected.