PHP Upload not add __ID__ to file name
PHP Upload not add __ID__ to file name
Hello, I'm using Editor and I'd like to add a file upload.
I have a mysql database with just a field for the file name (not path).
Here is my php code :
Editor::inst( $db, 'PITs', 'id' )
->fields(
Field::inst( 'nom' )
->validator( 'Validate::required'),
Field::inst( 'prenom' )
->validator( 'Validate::required'),
Field::inst( 'sexe' ),
Field::inst( 'num_secu' )
->validator( 'Validate::required')
->validator( function ( $val, $data, $field ) {
if( \IsoCodes\Insee::validate($val, 'FR')) return true;
else return "Entrez un numéro de sécu valide.";
}),
Field::inst( 'photo' )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'admin/photo_pits/__ID__.__EXTN__' ) ),
Field::inst( 'email' )
->validator( 'Validate::required')
->validator( 'Validate::email' ),
Field::inst( 'portable' )
->validator( 'Validate::required')
->validator( function ( $val, $data, $field ) {
if( \IsoCodes\PhoneNumber::validate($val, 'FR')) return true;
else return "Entrez un numéro de portable valide.";
}),
Field::inst( 'adresse' ),
Field::inst( 'ville' ),
Field::inst( 'code_postal' )
->validator( function ( $val, $data, $field ) {
if( \IsoCodes\ZipCode::validate($val, 'FR')) return true;
else return "Entrez un code postal valide.";
}),
Field::inst( 'centre_id' )
->validator( 'Validate::required'),
Field::inst( 'badge_id' )
)
->process( $_POST )
->json();
I'm expecting the file to be upload in /admin/photo_pits/ with a name like 163.png with 163 = the id of the mysql row ...
And this is the json I received (file is also saved with just .png name, no Id or content whatsoever):
{"data":[],"files":[],"upload":{"id":"\/var\/www\/admin\/photo_pits\/.png"}}
Any idea why ID is null ?
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You haven't provided it with any information about the database for the files table. This section of the manual will hopefully be helpful.
Allan
ohh ok !
It was not clear for me on the doc.
Working now, thanks a lot !
Denis