Use PHP functions in JavaScript

JavaScript sha1_file

Calculate the sha1 hash of given filename

1
2
3
4
56
7
8
9
1011
12
13
function sha1_file ( str_filename ) {
    // Calculate the sha1 hash of given filename  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/sha1_file    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: file_get_contents
    // -    depends on: sha1
    // *     example 1: sha1_file('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '40bd001563085fc35165329ea1ff5c5ecbdbbeef'    var buf = this.file_get_contents(str_filename);
    return this.sha1(buf);
}
external links: original PHP docs | raw js source

Examples

Running

1
sha1_file('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');

Should return

1
'40bd001563085fc35165329ea1ff5c5ecbdbbeef'

Dependencies

In order to use this function, you also need:

Open syntax issues

php.js uses JsLint to help us keep our code consistent and prevent some common bugs.

Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.


Authors

Thanks to the following developers, you get to have sha1_file goodness in JavaScript.

Comments

Add Comment
Use:
[CODE]
your_stuff('here');
[/CODE]
for proper code formatting
By submitting code here you are allowing us to use it in php.js hence dual licensing it under the MIT and GPL licenses

Gravatar
Kevin van Zonneveld
8 Feb '08 Permalink

q  @ marrtins: Thank you, it was an incompatibility between the updated addslashes & stripslashes functions and Dean Edward's Packer.

Fixed by putting the regexes between quotes.

Gravatar
marrtins
8 Feb '08 Permalink

q  Hi!

It seems, that php.packed.js is broken. Firebug reports: unmatched ) in regular expression


Contribute a New function