We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Create an new file instance

In phalcon you can get uploaded file with this piece of code

    //Check if the user has uploaded files
    if ($this->request->hasFiles() == true) {
        //Print the real file names and their sizes
        foreach ($this->request->getUploadedFiles() as $file){
            echo $file->getName(), " ", $file->getSize(), "\n";
        }
    }

each $file is an Phalcon\Http\Request\File instance.

But what if I want to create an file instance from an existing file on the server, how can I do that?

What I tried is this:

    new Phalcon\Http\Request\File(array($fileDir));

But it returns an instance with empty properties.

any help would be appreciated :D



1.5k

It would be verry usefull to reuse the File class!

But if it is not possible, I can write one myself so al the file data is stored in one object. Which would help me to prevent googling how to read,write,move or copy a file and its properties in plain php