Skip to main content
Inspiring
February 10, 2009
Answered

String index out of range: -22

  • February 10, 2009
  • 5 replies
  • 1942 views
I'm getting the error message "String index out of range: -22" for my cffile upload, Here's the cffile code. The error says it is happening on the cffile line.

<cffile action="upload" filefield="form.new_file" destination="X:\Inetpub\wwwroot\Training\NewSite" nameconflict="OVERWRITE">

The file is being sent by the form below:
<cfform action="ilearntutorialchange.cfm" method="POST" name="theaddition" enctype="multipart/form-data">

<input type="File" name="new_file">

<input type="submit" name="add" value="Add">

Dumping the variables on the page gives me
new_file = E:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp22674.tmp
add = add
fieldnames = add, new_file

I'm using MX 7. If I try to upload a file off the same server I get "string index out of range: -2" I've tried looking in the cf administrator but I'm not finding where I check on the settings of cffile. If I need to make changes in the administrator can someone point me to where this is?
Thanks
    This topic has been closed for replies.
    Correct answer wam4
    Thanks for all the tips. I finally got it working on the test box using MX7 but not on the production server (go figure).

    This code works
    <cffile action="upload" filefield="new_file" destination="/Inetpub/wwwroot/mysite/subfolder" nameconflict="MAKEUNIQUE">

    This might help others to know that String Index out of range is one of those error messages that fits numerous error scenarios. I started noticing that changing the destination path, changed the number in the error message as in "String index out of range: -17 or -22 or -2 or -10"

    For others with the same issue try looking at the destination path first. Thanks again for the help.

    5 replies

    wam4AuthorCorrect answer
    Inspiring
    February 11, 2009
    Thanks for all the tips. I finally got it working on the test box using MX7 but not on the production server (go figure).

    This code works
    <cffile action="upload" filefield="new_file" destination="/Inetpub/wwwroot/mysite/subfolder" nameconflict="MAKEUNIQUE">

    This might help others to know that String Index out of range is one of those error messages that fits numerous error scenarios. I started noticing that changing the destination path, changed the number in the error message as in "String index out of range: -17 or -22 or -2 or -10"

    For others with the same issue try looking at the destination path first. Thanks again for the help.
    Inspiring
    February 10, 2009
    > This is a guess.

    Come on Dan. Your favourite saying is "if you don't have the docs, the
    internet does".

    I only draw attention to this because your advice is dead wrong:


    > You need octothorps around your form variable in your cffile tag.

    (from *the docs*: http://livedocs.adobe.com/coldfusion/8/Tags_f_10.html)

    fileField (Required)
    Name of form field used to select the file.
    Do not use number signs (#) to specify the field name.


    Back to the original problem, I used to see that quite a lot on CFMX 6.1
    (maybe early versions of CFMX7), when CF was cocking-up (technical term)
    the compilation of CFM templates.

    I've not seen it in situations other than that.

    Tell me: have you got your class files set to save? Perhaps delete
    everything in your cfclasses dir (WEB-INF/cfclasses on multi-server
    install. Not sure where it is on a standard install, sorry), restart CF
    and try again.

    --
    Adam
    wam4Author
    Inspiring
    February 10, 2009
    It may be an MX7 issue. We have CF 8 up as a test server (for now) and it works fine on that one and you can't have the hash marks on the filefield variable. I'm chalking it up to that.
    wam4Author
    Inspiring
    February 10, 2009
    changing the cffile code to:
    filefield="#form.new_file#"

    gives me the new error :
    The form field "E:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp22678.tmp" did not contain a file
    Inspiring
    February 10, 2009
    This is a guess.

    You need octothorps around your form variable in your cffile tag.