110 points · by nikosch86 · 6y ago · 30 comments
Also perhaps consider the `mkdir` function, and perhaps 'file_put_contents'. Your reliance on shell functions via `exec` is quite concerning, given what you're doing.
Lastly, I'd suggest either `random_int` or `random_bytes` (combined with e.g. bin2hex, or a hashing function to get an ascii string) instead of uniqid.
I'm not quite sure why there's a check on user agent, to carry out the same logic regardless?
the user agent check was a relic from when it behaved differently, browser vs curl, it is not needed anymore and has been removed. Pull Request are always welcome
edit: I also just pushed an update to use bin2hex(random_bytes(16)) instead of uniquid to make sure we never have collisions, for arguments sake (even though I thought that risk was rather low to begin with)
I agree that uniqid(), as used, is not the best choice, but that's only because it may produce dupes if the machine's clock is rolled back (ie by ntpd). Regardless of the prng choice, the code could use a check for whether selected folder already exists.
Any use of `exec` should be considered dangerous, when there's native language/stdlib support for achieving the same thing.
Edit: corrected function name.
This is akin to using "if (3 == x)" notation in C in a fear of accidentally writing "if (x = 3)".
For this particular case the use of both `rename` and `exec` would've been perfectly fine.
> Any use of `exec` should be considered dangerous
By whom? It may be a red flag if used by an inexperienced programmer or if it appears in an otherwise messy code base. But if I know what I'm doing, then it's just another API that's perfectly OK when used with due care.
[1] https://github.com/dutchcoders/transfer.sh/
Edit: Since more than one person has replied with non-self-hosted solutions, I should note that transfer.sh can be self-hosted, although you can also use the website itself.
If one needs more features or more control, there are certainly many options out there, I created this not to compete with other projects but to provide a super simple solution to a specific problem.
It even has a useful Thunderbird extension that auto-uploads any large attachment using the FileLink API when composing a new mail, adding the dl URL in the email's body. Unfortunately the extension stopped working after the migration to WebExtensions.