phpweb-applicationspike

Can anyone explain this code? How could it be emulated with PHP?


So I'm trying to make a relatively complicated php script, using some code written in pike. The full source code is available here: http://www.text-image.com/pic2html.pike . It's only a learning experience really, as I'm not going to release it. However I would like to get it working!

int main(int arg 

            if (temp > 10485760) {
                werr("Image too large (10MB limit).");
                return 0;
        }

        string info = Stdio.stdin.read(temp);

        if (strlen(info) < temp) {
                werr("Insufficient data uploaded.");
                return 0;
        }

I understand the if statement on line 3."If the integer 'temp' is larger then 10485760, execute function 'werr' with the string ('Image too large (10MB limit.');

I also understand the if statement on line 8, which is very similar to the first statement.

What I don't understand is the

string info = Stdio.stdin.read(temp);

I don't understand the

int main(int arg 

If I had to guess, I'd say the result of the function would be applied to an integer called 'main'? Is that right? How could this be emulated in php?

Thanks for your time!


Solution

  • I don't know this language, but seems very similar to C++.

    The:

    int main(int arg 
    

    is the beginning of the main function wich doesn't exist in PHP therefore you can just omit it. In compiled languages the main function is the first function to be called when the program starts. In PHP the file requested is just executed line per line.

    And the:

    string info = Stdio.stdin.read(temp);
    

    feels like:

    std::string info;
    std::cin >> info;
    

    which just read from the standard input stream. There's nothing such a thing as iostream in PHP, the inputs are cookies, POST, GET, DELETE, PUT etc. and are made per request.