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

Upload different images in different fields

I am uploading my image and using the method of documentation

use Phalcon\Mvc\Controller;

class PostsController extends Controller
{
    public function uploadAction()
    {
        $imagenes = new TablaImagenes();

        // 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) {
                $imagenes = new TablaImagenes();
                $imagenes->direccion=   'img/imagenes' . $file->getName();
                $file->moveTo('img/imagenes/' . $file->getName());
                $imagenes->save();
            }
        }
    }
}

But I need to specify different images for different fields


$imagenes ->cedula= $imagen1->getName();
$imagenes ->contrato= $imagen2->getName();
$imagenes ->croquiz=  $imagen3->getName();
$imagenes ->moveTo('img/cedula/' . $imagen1->getName());
$imagenes ->moveTo('img/contrato/' . $imagen2->getName());
$imagenes ->moveTo('img/croquiz/' . $imagen3->getName());

How can I specify which image will be saved in that field?

edited Nov '16

getKey will reiturn field name i think. Just write proper loop and conditions