Answer the question
In order to leave comments, you need to log in
How to properly load functions from files in PHP?
Hello connoisseurs! I have a question for you: how to correctly build a structure and load the necessary function from a file? I am making a small script that will upload pictures to photo hosts, such as imgur, making all photo hosts in 1 file does not seem like the best idea, over time there will be more than 50 of them, it is planned to set the necessary photo host in config.ini. And the question is: how to call a function from a file, depending on the one specified in config.ini, the scripts themselves are planned to be stored in /hosts/ , and named imgur.com.php in this way. In the configuration file, they will be set with the short entry "imgur", i.e. when choosing imgur, you need the initializer script to call the file /hosts/imgur.com.php . Interested in your opinion, how it will still be more correct, or maybe you shouldn’t do this and it’s better to add all photo hosts to 1 file? Thank you.
And an additional question: how to call the curl function in each file so as not to duplicate the code?
Answer the question
In order to leave comments, you need to log in
I think you have answered your own question.
Take the hostname and do include or require. It can be moved to a class and added to autoloader.
Regarding curl, the same thing, take the code into a separate function (maybe also into a separate include file) and do not duplicate it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question