Upload / Filter the files from the metadata tables
Upload / Filter the files from the metadata tables
Good morning,
I have an issue with upload class in PHP.
I am using it to upload images for a web application. Images are segregated per user and per entity.
When I use ->upload() the web service returns ALL the images recorded into the metadata table. I would like to filter only the relevant images. I did not find any example or snippet.
Essentially I need to add a where clause somewhere.
This is my code.
Field::inst( 'child_information.document_id' )
->setFormatter( 'Format::ifEmpty' , null )
->upload( Upload::inst( function ( $file, $id ) {
try {
$_directory = getenv('DOCUMENT_PHISICAL_PATH') . '/' . $_SESSION['account_id'] .'/';
// Move files into dedicated directory
move_uploaded_file( $file['tmp_name'], $_directory . $id . '.' . pathinfo( $file['name'], PATHINFO_EXTENSION) );
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
return $id;
} )
->db( 'document', 'id', array(
'original_file_name' => Upload::DB_FILE_NAME,
'file_size' => Upload::DB_FILE_SIZE,
'file_extension' => Upload::DB_EXTN,
'type_id' => 'DO',
'entity' => 'schedule_document',
'account_id' => $_SESSION['account_id']
) )
->validator( function ( $file ) {
return$file['size'] >= 15000000
? "Files must be smaller than 15mB"
: null;
} )
->allowedExtensions( [ 'png', 'jpg', 'pdf', 'doc', 'docx' ], "Please upload an image, a PDF/Word file." )
),
Could you help?
Thanks,
Fabio
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Fabio,
The
Uploadmethod has awheremethod which you can use to do what you are looking for.Allan
Thanks.
Edited like this and it worked.