r/CodingHelp • u/SzLRichard1 • Jul 26 '22
[Random] How can I make a website download a randomly chosen file from a selection of files?
By website I mean like the url-s that only do one thing, start a download. I want something similar to what SethBling did when he did a random drop data pack for minecraft. I don't know if he did it by creating every possible combination and randomly choosing one to download or by making the download link randomly modify the file. I would assume it's the second one but I don't know how to do either of the possibilities. Does someone know how he did it or how I could do something similar? (I am not doing anything related to minecraft, so don't go into minecraft details). Thank you for your responses in advance.
2
u/LucienMr Jul 26 '22
I can’t understand if you mean you’ll have a website that downloads files from other people, or if you have a website with your own files on your own server.
If it’s the second one, it’s honestly super easy. In PHP there’s a scandir function which returns all file names in a directory. Put all those into an array and randomly choose one, then use that randomly chosen output as the file name to download.
I would recommend looking at PHPs scandir function then find out the equivalent in whatever language you’re using.
If it’s the first choice, however, I have no clue. I have theoretical knowledge on scanning webpages but I’ve never done it.
5
u/Nightcorex_ Jul 26 '22
First of all I do not know who "SethBling" is, and I don't know what a "drop data pack" is (is it the successor of texture packs?).
Again I don't know "drop data packs" or how many variations there are. If there are only a few variations then this might be very well it, if there are millions+ of variations however then this definetly isn't the approach to go.
That makes absolutetly no sense. A link can't magically modify a file.
I think the most reasonable approach is to have a backend that generates a new random variation on the fly, then send it back to the client to download it.