rejetto forum

Rename on Upload

raybob · 16 · 3241

0 Members and 1 Guest are viewing this topic.

Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
My knowledge is pretty limited and I seem unable to figure this out, could anybody help?  (I'm using HFS 2.3 b274)

Well, pretty much I just want to make it so that when a user uploads a file, HFS automatically appends the name of the file to something else, and then shows it as such in the upload results page.  I created a javascript for a random string of letters and numbers, and I want to make it so that if somebody uploaded "document.txt", using the JS it would be changed to something like "9SLQN3TYE6RPBW4Y7GLTLX2L9IQNY40N____document.txt" .  I'm assuming this could be done with Macros with something along the lines of     .rename.| "(my javascript)" + "____" + "%item-name%" |   but I'm not sure and I'm really not familiar with HFS macros.

Better yet, I need this to be done in the template rather than in HFS.events because I only want it to happen in one part of my site for extra security.

An even more amazing feat (that I have no idea how to do) would be to have it take off the first 32 characters on a file name when downloading the file so that the random string is gone . . .



Thanks,
Raybob
« Last Edit: February 19, 2011, 04:31:57 PM by raybob95 »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2004
    • View Profile
http://www.rejetto.com/forum/index.php/topic,6845.msg1042396.html#msg1042396

look at section
[upload name]
%item-name%            (it is the default value to be used or nothing)

the section is evaluted and return a text as new name

[upload name]
uploaded_by_%user%_%item-name%

[upload name]
{.if|{.%folder-name% = upload.}|uploaded_by_%user%_%item-name%|%item-name%.}

..... etc  ;)


Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
Is there a way to put that in the template rather than HFS Events so that it only happens in one section of the VFS?


Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
But first I need to know, how would I go about putting the script for the random string into the upload name spot anyway?

This doesn't work and neither does just putting the javascript under the [upload name]


Code: [Select]

For help on how to use this file please refer http://www.rejetto.com/wiki/?title=HFS:_Event_scripts

[upload name]
%random%----%item-name%


[random]

<script type="text/javascript">

var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var length = 32;
var string = '';

for (var i=0; i<length; i++)

{
var rnum = Math.floor(Math.random() * characters.length);
string += characters.substring(rnum,rnum+1);
}

document.write( string + "____" + "%item-name%" )

</script>

« Last Edit: February 20, 2011, 01:32:08 AM by raybob95 »


Offline SilentPliz

  • Operator
  • Tireless poster
  • *****
    • Posts: 1297
  • ....... chut ! shh!
    • View Profile
Hi  :)

Try this, it's more simpler that your JS


[upload name]
{.random number | 1000000000000000 | 9999999999999999.}____%item-name%


You can also reserve this option to some file type.

example:

[upload name]
{.switch|%item-ext%|,|jpg,gif,png,doc,txt|
{.random number | 1000000000000000 | 9999999999999999.}____%item-name%
.}

« Last Edit: February 20, 2011, 03:26:20 PM by SilentPliz »


Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
Thanks!  To get a more random number (it was coming out with the first 8 digits always 9's ) I put random number 0 | 9 and then pasted it sixteen times and it works great!

Anyway is there any way to put this in the template or at least have it so it only does this when in a certain folder?

Thanks,
Raybob
« Last Edit: February 20, 2011, 04:16:09 PM by raybob95 »


Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
YES!!!!

Thank you all so much I got it to work properly . . .  Now it only appends the file name when uploading to the folder that people can upload to but not browse . . .

Code: [Select]


[upload name]
{.if|{.%folder-name% = private.}|{.random number | 1 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}

{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random

number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 |

9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random

number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 |

9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random

number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 | 9.}{.random number | 0 |

9.}{.random number | 0 | 9.}{.random number | 0 | 9.}----%item-name% |%item-name%.}





Offline SilentPliz

  • Operator
  • Tireless poster
  • *****
    • Posts: 1297
  • ....... chut ! shh!
    • View Profile
{.random number | 1000000000000000 | 9999999999999999.}____%item-name%

give more digit... pasted once time ;D


Offline SilentPliz

  • Operator
  • Tireless poster
  • *****
    • Posts: 1297
  • ....... chut ! shh!
    • View Profile
Anyway is there any way to put this in the template or at least have it so it only does this when in a certain folder?

Better idea by Mars:

Add this section to the diff template tab of your choosed folder(s):
VFS ->> selected folder ->> properties ->> diff template - or inside the hdd folder create a file named hfs.diff.tpl with the code -


[upload-success]
{.set|length|22.}
{.set|prefix|FILE_.}
{.set|random-name|{:{.set|result.}{.for|j|1|$1|{:{.set|result|{.^result.}{.random|0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z.}.}:}/for.}{.^result.}:}/set.}
{.set|item-name|{.^prefix.}{.replace| ||{.upper|{.^random-name|{.^length.}.}/upper.}.}__%item-name%/set.}
{.rename|%folder-resource%\%item-name%|%folder-resource%\{.^item-name.}.}
{.inc|ok.}
<li><a href='{.filepath|%item-url%.}{.^item-name.}'>{.^item-name.}</a>
<br />%item-size% @ %speed% KB/s
{.if| %user% |{: {.append| %folder-resource%\hfs.comments.txt |{.^item-name.}=uploaded by %user%
/append.} :}/if.}



note:
22 is the length of the random string added between the prefix FILE_ and the source filename

You can only remove FILE_ and/or change the value 22, but nothing else.
« Last Edit: February 20, 2011, 10:58:39 PM by SilentPliz »


Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
I've settled on this and it works sufficiently.

It's just so anybody can upload without an account and then choose who they share their files with.  The folder these are uploaded to isn't browse-able a the folder uses a special template.

Code: [Select]
For help on how to use this file please refer http://www.rejetto.com/wiki/?title=HFS:_Event_scripts

[upload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C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}{.random|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}{.random|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}{.random|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}{.random|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}{.random|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}{.random|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}----%item-name% |%item-name%.}






Example:

« Last Edit: February 28, 2011, 03:41:50 AM by raybob95 »


Offline SilentPliz

  • Operator
  • Tireless poster
  • *****
    • Posts: 1297
  • ....... chut ! shh!
    • View Profile
Hi ! :)

Waaw! It's an panoramic code that you show us here! 8) :D

Try anyway the script above, you will have more options in choosing the location where you will use it, for given some rights, or for restrict users.

 ;)



Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2004
    • View Profile
Your code is too long, all the lines with random can be put in a single loop

Quote
For help on how to use this file please refer http://www.rejetto.com/wiki/?title=HFS:_Event_scripts

[upload name]
{.if|{.%folder-name% = private.}|{:{.for|loop|1|32|{.random|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z.}/for.}:}----/if.}%item-name%


Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
^ I did that, and believe it or not the code wasn't very random; the first 16 characters were always nines and from then on it seemed to want to always pick similar strings.  I put it the way I did and it works fine and is completely random.  There's nothing detrimental about the way I put it is there?  Seems to work fine . . .

Since you guys seem so keen to help me  ;D is there a way to make it so that when downloading a file, it removes the first 36 characters so that the original name is restored?

Raybob
« Last Edit: February 28, 2011, 08:06:38 PM by raybob95 »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
yes, it's possible, just use the event [download name]
and you can manipulate the name
i'm not sure but something like this may work
{.cut|36||%item-name%.}


Offline raybob

  • Tireless poster
  • ****
    • Posts: 453
    • View Profile
    • FileSplat.com
Thanks!

I'm using this and it seems to work perfectly, although I'm not sure why but I had to use 37 or a " - " was left at the beginning of every file name.

Code: [Select]
[download name]
{.if|{.%folder-name% = private.}|{.cut|37||%item-name%.}|%item-name%.}
« Last Edit: March 01, 2011, 08:40:48 PM by raybob95 »