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

Phalcon\Http\Request\File moveTo()

Hi, I try to use native method moveTo(). My version Phalcon last build 1.2.0 method moveTo() dont upload files.

 foreach ($this->request->getUploadedFiles() as $key => $file) {
            $name = sha1($file->getName()[$key]) . '.' . pathinfo($file->getName()[$key], PATHINFO_EXTENSION);
            $destination = $uploadDir.DIRECTORY_SEPARATOR.$name;
            //this not work
            //$file->moveTo($destination);
           // this work correctly
            move_uploaded_file($file->getTempName()[$key], $destination);
 }


7.1k

else in documentation https://docs.phalcon.io/en/1.1.0/api/Phalcon_Http_Request_File.html public string getName () but it return array



98.9k

Currently that class does not support an array of files in the same index, that's why it's returning an array instead of a string



7.1k

Why moveTo () does not work? It is better not to use this class and work with the $ _FILES?



98.9k

This class is expecting a single file in the $_FILES superglobal if you pass an array of files the data would not be that it's expecting.

If you pass this it will not work

<input type="file" name="my_file[]">
<input type="file" name="my_file[]">
<input type="file" name="my_file[]">

But if you pass this it works:

<input type="file" name="my_file1">
<input type="file" name="my_file2">
<input type="file" name="my_file3">

Or you can create the Phalcon\Http\Request\File from the array of files:

foreach ($_FILES as $key => $uploadedFiles) {
    foreach ($uploadedFiles as $uploadedFile) {
        $file = Phalcon\Http\Request\File($uploadedFile);
    }
}


7.1k

ok thanks your solution works correctly.