rename file by md5 hash at jquery file upload - jquery-file-upload

i am useing jquery file upload (php) lastest ver,
i want rename a upload file by file md5 hash,
i have tried this method
md5(time().$file_name_only[0]).$extension ;
but only hash the time, how can i get the file md5 hash and rename by only md5?
( i dont want to hash of filename, i want hash of file )
thanks for any help :)

You can use
string md5_file ( string $filename [, bool $raw_output = false ] )

Related

Stata append datasets using foreach and local

I'm trying to append many files in Stata using loop. I've tried this answer: Stata: looping and appending
And below is my code.
clear
local pathdir "Data\RawData\edd"
local files: dir "`pathdir'" files "test_*.dta"
save "`pathdir'/master.dta", emptyok replace
foreach file in `files' {
use "`pathdir'/`file'", clear
append using "`pathdir'/master.dta"
save "`pathdir'/master.dta", replace
}
It just gives me empty space. I'm not really sure what to do. Why doesn't this work? Thank you for any help.
Let me just add that looping to append files is not necessary.
clear
local pathdir "Data\RawData\edd"
local files: dir "`pathdir'" files "test_*.dta"
append using `files'
save "whatever.dta"

Run for-loop only if there is at least one json file

I want to iterate over all json files in a specific subdirectory.
#!/bin/sh
source_dir="nodes"
for file_path in $source_dir/*.json;
do
file_name=$(basename $file_path .${file_path##*.})
echo $file_name
done
My code is working as expected if there is at least one json file in the directory.
If there is no json file in the directory, the loop will still be executed. The file_name is then "*".
How do I have to change the for loop so that it is only executed if there is at least one json file in the directory?
you can wrap you loop in an if clause to check if the pattern matches anything.
Check this SO question on how to do this: Check if a file exists with wildcard in shell script

Perl script to check file exists in Linux file system

I am working on production servers.. I want to check file generated daily and send report via email like file generated or not daily.. I like to use perl script and I might run the script on different server so my script should check on other server where file generates. And also it check for file header and trailer. Please guide me how to check in different system and how to generate as mail content depends upon file exists or not conditions I.e if all file exists content something like all file generated and it contain table with filename and status of the file exists . if file not exists file name should be highlighted and content should be like missing file not generated please investigate... Give me some ideas around this.. Thanks
Summaries:
Just check file exists or not with header and trailer check . generate as a mail with table format of filename and status as 1or 0. If not generated highlight those files using perl
You can check if a file exists using
if(-e "filename"){
#file exists
}
else{
#file does not exist
}
And also it check for file header and trailer.
Not sure what you mean with this, but I guess once you verified that the file exists you can just read its content to check it:
open FILE, "filename" or die "Error opening file!\n"
while(my $line=<FILE>){
#process line
}

Perl write to file returns huge weird stacktrace

I have the following problem: when I try to save the file that contains a semicolon in the name it returns a huge and weird stacktrace of the characters on the page. I've tried to escape, to trim and to replace those semicolons, but the result is still the same. I use the following regex:
$value =~ s/([^a-zA-Z0-9_\-.]|;)/uc sprintf("%%%02x",ord($1))/eg;
(I've even added the |; part separately..)
So, when I open the file to write and call the print function it returns lots of weird stuff, like that:
PK!}�3y�[Content_Types].xml ���/�h9\�?�0���cz��:� �s_����o���>�T�� (it is a huge one, this is just a part of it).
Is there any way I could avoid this?
Thank you in advance!
EDIT:
Just interested - what is the PK responsible of in this string? I mean I can understand that those chars are just contents of the file, but what is PK ? And why does it show the content type?
EDIT 2.0:
I'm uploading the .docx file - when the name doesn't contain the semicolon it works all fine. This is the code for the file saving:
open (QSTR,">", "$dest_file") or die "can't open output file: $qstring_file";
print QSTR $value;
close (QSTR);
EDIT 3.0
This is a .cgi script, that is called after posting some data to the server. It has to save some info about the uploading file to a temp file (name, contents, size) in the manner of key-value pairs. So any file that contains the semicolon causes this error.
EDIT 4.0
Found the cause:
The CGI param function while uploading the params counts semicolon as the delimiter! Is there any way to escape it in the file header?
The PK in file header it means it is compressed ZIP like file, like docx.
One guess: The ; is not valid character in filename at the destination?
Your regexp is not good: (the dot alone is applicable to any character...)
$value =~ s/([^a-zA-Z0-9_\-.]|;)/uc sprintf("%%%02x",ord($1))/eg;
Try this:
#replace evey non valid char to underscore
$value =~ s/([^a-zA-Z0-9_\-\.\;])/_/g;

How can I extract a single file from a ZIP archive using Perl's Archive::Zip?

I have a zip file X and I'd like do extract a single file, located in x/x/x/file.txt. How do I do this using Archive::Zip and Perl?
You can use the extractMember method:
extractMember( $memberOrName [, $extractedName ] )
Extract the given member, or match its name and extract it. Returns undef if member doesn't exist in this Zip. If optional second arg is given, use it as the name of the extracted member. Otherwise, the internal filename of the member is used as the name of the extracted file or directory. If you pass $extractedName, it should be in the local file system's format. All necessary directories will be created. Returns AZ_OK on success.
See Archive::Zip::FAQ, "extract file(s) from a Zip". The current version of the example file is online at http://cpansearch.perl.org/src/ADAMK/Archive-Zip-1.30/examples/extract.pl.