I ran into this problem when uploading a file with a super long name - my database field was only set to 50 characters. Since then, I have increased my database field length, but I'd like to have a way to check the length of the filename before uploading. Below is my code. The validation returns '85' as the character length. And it returns the same count for every different file I upload (none of which have a file name length of 85).
<cfscript>
missing_info = "<p>There was a slight problem with your submission. The following are required or invalid:</p><ul>";
// Check the length of the file name for our database field
if ( len(Form["ResumeFile1"]) gt 100 )
{
missing_info = missing_info & "<li>'Resume File 1' is invalid. Character length must be less than 100. Current count is " & len(Form["ResumeFile1"]) & ".</li>";
validation_error = true;
ResumeFileInvalidMarker = true;
}
</cfscript>
Anyone see anything wrong with this?
Thanks!
http://www.cfquickdocs.com/cf9/#cffile.upload
After you upload the file, the variable "clientFileName" will give you the name of the uploaded file, without a file extension.
The only way to read the filename before you upload it would be to use JavaScript to read and parse the value (file path) in the file field.
A quick clarification in the wording of your question. By the time your code executes the file upload has already happened. The file resides in a temporary directory on the ColdFusion server and the form field related to the file upload contains the temporary filename for that file. Aside from checking to see if a file has been specified, do not do anything directly with that file or you'll be circumventing some built in security.
You want to use the cffile tag with the upload action (or equivalent udf) to move the temp file into a folder of your choosing. At that point you get access to a structure containing lots of information. Usually I "upload" into a temporary directory for the application, which should be outside of the webroot for security.
At this point you'll then want to do any validation against the file, such as filename length, file type, file size, etc and delete the file if it fails any checks. If it passes all checks then you move it into it's final destination which may be inside the webroot.
In your case you'll want to check the cffile structure element clientFile which is the original filename including extension (which you'll need to check, since an extension doesn't need to be present and can be any length).
Related
Apologies, I am quite new with AHK.
Context: I am trying to build a small program (eventually with UI) which will clean data in .XLF files in order to be processed properly by a CAT tool interpreter (import into it).
By "clean" I mean to find HTML attributes and replace them with their respective Char Entities. This as a single script; writing the name of the file or path inside the script is working perfectly.
Problem: I would like to run my .ahk/.exe allowing the user to open the file manager/explorer and select the file that needs to be processed by the script (find/replace html attributes with char entities) selecting the file is not working. Nothing is populated (the final file/result is empty) I'm trying to sort out this with FileSelectFile function and store the output var value (selecting the file) in the first instruction "fileread, selectedfile".
But it's not working! If I don't do this and I only provide in the default directory "A_ScriptDir" an specific file name .xf -> this works fine.
This is my code so far w/comments:
SetWorkingDir, %A_ScriptDir%
FileEncoding, UTF-8
;NoEnv
;Open Window File Manager/Explorer and select a file .xlf file
FileSelectFile, SelectedFile, 8, , Open a file, , ,(*.xlf)
;--- > HTML attribute '&' must be replaced by its char entity first/overall otherwise this instruction will overwrite the amp entities from the rest of char entities corrupting the file;
;"SelectedFile" can be any filename such as "example.xlf" but this is not my scope
fileread, text, SelectedFile ;previously "text.xlf" with random html content to do tests
replace := "&"
newtext := strreplace(text, "&", replace, all)
sleep, 200
filedelete, newtest.xlf
fileappend, %newtext%, newtest.xlf
;--------------------------------- <b>
;here "fileread" must read the final appended file as solution to use "streplace" function multiple times (replace more than one desired string) running the script at the same time. (due to my lack of exp. with loop function)
fileread, text, newtest.xlf
replace := ">b<"
newtext := strreplace(text, "<b>", replace, all)
filedelete, newtest.xlf
fileappend, %newtext%, newtest.xlf
I've been thinking that other solution can be:
I am still new to understand apply Drag and Drop GUI but I am unsure how to modify my code in order to drag/drop a file onto the ahk.exe
Thanks for your time reading this! any tip and/or help would be super appreciated :)
The FileRead command expects text, not an input variable.
So if you add % around SelectedFile like this, it should work:
FileRead, text, %SelectedFile%
If that doesn't work, it means the file does not exist or an error occurred. In that, you'll want to look at FileRead's error handling section.
I am uploading a file, that contains spaces in the name, to Amazon S3 using cffile action="upload". The file name is burger+beans n beetroot.jpg.
As you can see, the name contains spaces and a plus sign.
When I read the directory, to list the contents, the file name returned by ColdFusion in the query is: burger+beans+n+beetroot.jpg. However, when viewing the file using Amazon S3 Browser, it is correctly listed as: burger+beans n beetroot.jpg. So it appears ColdFusion is replacing the spaces with + signs.
Does anyone know why this happens and if there is a way to disable this? I tried using both the DirectoryList() method as well as the <cfdirectory action="list"> tag, and both do this.
Please note: I am aware that the file name could be cleaned up before processing - that's a workaround, but not the solution I am looking for. Thanks!
I believe this is not a CF problem, it's a S3 problem. They send out their file names escaped. Which makes this a non-answer.
I created a folder in a S3 bucket. Then I uploaded a file named burger+beans n beetroot.jpg. I can see in AWS' console the file properly named. I select it, then in the Actions menu select Download. I get the modal window. Take a look at the URL in the browser footer - the file name is escaped.
I right-click their link and choose "Save Link As..." - the file name is escaped as well.
So I don't think there is anything you can do once the file is up there. You'll need to clean it before uploading. I know it's not what you want to hear.
Try URL encoding the filename, so the + sign will be converted to an url encoded space (%2b). You could use URLEncodedFormat, but make sure that the path to the file isn't urlencoded as well.
I have a list of MD5 hash of files stored in a text file. And I want delete them all when it been found on system or a path. But I have problem to code it. I have tried to but it only scan one file from listed MD5 so its not what i needed. Is there any way to find them and deleted files which there MD5 hash's are listed in a path. Thanks.
pidgin pseudocode:
put md5s in array
cycle through a filesystem
for each file, put into varable, compute md5hash of variable
if md5hash is in array, delete file
maybe you should skip swap files and system folders.
As per my requirement, I need to upload a .csv file into the application. I am trying to simulate this using loadrunner. The issue I am encoutering is that my csv file is in the below format
Header - AA,BB,CC
Data-xyz,"yyx,zzy",xxz
On using the below statement to upload the file, I am getting an error ""line 2 contains 4 columns instead of 3"
web_submit_data("upload",
"Action=xxx/upload",
"Method=POST",
"EncType=multipart/form-data",
"RecContentType=text/html",
"Referer=xxx",
"Snapshot=t86.inf",
"Mode=HTML",
ITEMDATA,
"Name=utf8", "Value=✓", ENDITEM,
"Name=token", "Value={token_1}", ENDITEM,
"Name=upload_file", "Value={NewParam_5}", "File=yes", "ContentType=text/csv", ENDITEM,
"Name=Button1", "Value=Upload", ENDITEM,
LAST);
AS per information provided in How to deal with a string with comma in it from a csv, when we have to read the data by using loadrunner? ,
I tried updating the .prm file to a new delimiter pipe, | but still i get the error.
[parameter:NewParam_5]
Delimiter="|"
ParamName="NewParam_5"
TableLocation="C:\temp"
ColumnName="Col 1"
I also notice that even though I set the delimiter to pipe, if I rightclick on the web_submit_data() and go to Parameter properties, i see a column delimiter option there as well and it is not set to pipe and is set to comma which indicates that this setting is taking higher precedence to the setting in .prm file.
Can someone please guide me the right way to set a new delimiter so that vugen recognizes and parses the csv file as I want it to.
I am using loadrunner 12.5
Thanks for your help.
Do you need to upload a file or a line of comma separated variables? Right now you appear to be reading a line of CSV variables, not a file as your parameter file would contain a list of filenames or a single file reference within the directory of the virtual user (extra files, transferred with the use) or created by the virtual user and then uploaded.
is it possible to load module from file with extension other than .lua?
require("grid.txt") results in:
module 'grid.txt' not found:
no field package.preload['grid.txt']
no file './grid/txt.lua'
no file '/usr/local/share/lua/5.1/grid/txt.lua'
no file '/usr/local/share/lua/5.1/grid/txt/init.lua'
no file '/usr/local/lib/lua/5.1/grid/txt.lua'
no file '/usr/local/lib/lua/5.1/grid/txt/init.lua'
no file './grid/txt.so'
no file '/usr/local/lib/lua/5.1/grid/txt.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './grid.so'
no file '/usr/local/lib/lua/5.1/grid.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
I suspect that it's somehow possible to load the script into package.preaload['grid.txt'] (whatever that is) before calling require?
It depends on what you mean by load.
If you want to execute the code in a file named grid.txt in the current directory, then just do dofile"grid.txt". If grid.txt is in a different directory, give a path to it.
If you want to use the path search that require performs, then add a template for .txt in package.path, with the correct path and then do require"grid". Note the absence of suffix: require loads modules identified by names, not by paths.
If you want require("grid.txt") to work should someone try that then yes, you'll need to manually loadfile and run the script and put whatever it returns (or whatever require is documented to return when the module doesn't return anything) into package.loaded["grid.txt"].
Alternatively, you could write your own loader just for entries like this which you set into package.preload["grid.txt"] which finds and loads/runs the file or, more generically, you could write yourself a loader function, insert it into package.loaders, and then let it do its job whenever it sees a "*.txt" module come its way.