Pass variable while inserting in to database
Pass variable while inserting in to database
This is the code I am uploading a file
Field::inst( 'a.cwwrwq_image_url' )
->setFormatter( Format::ifEmpty( null ) )
->upload( Upload::inst( '../m/ul/'.'__ID__.__EXTN__' )
->db( 'files', 'id', array(
**'img_type' => 'WSQA',**
'filename' => Upload::DB_FILE_NAME,
'filesize' => Upload::DB_FILE_SIZE,
'web_path' => Upload::DB_WEB_PATH,
'system_path' => Upload::DB_SYSTEM_PATH
) )
->validator( Validate::fileSize( 3000000, 'Files must be smaller that 3MB' ) )
->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
),
in ** img_type ** is insert DB_WEB_PATH
Answers
To be honest I don't know what those asterisks in this line mean:
I know that ** is the exponentiation operator in PHP. Does it really make sense to have those operators there? I am sure they will cause trouble. Why don't you remove them and try again?
https://www.php.net/manual/en/function.pow.php
I use this code - and it works perfectly fine:
Dear I put those stars to just point out the problem my code is
Field::inst( 'a.cwwrwq_image_url' )
->setFormatter( Format::ifEmpty( null ) )
->upload( Upload::inst( '../m/ul/'.'ID.EXTN' )
->db( 'files', 'id', array(
'img_type' => 'WSQA',
'filename' => Upload::DB_FILE_NAME,
'filesize' => Upload::DB_FILE_SIZE,
'web_path' => Upload::DB_WEB_PATH,
'system_path' => Upload::DB_SYSTEM_PATH
and it is not working it is not putting 'WSQA' in img_type field of DB
I think this error was fixed by this commit. It was included in Editor 2.3.2. What version of the PHP libraries are you using?
Allan
Wow! I am using Editor 2.0.7. The code of "private function _dbExec" in my file "Upload.php" is completely different from the one linked above. Mine works really well.
Thanks allan
I am using editor Editor 2.3.2, I followed your instruction and updated upload.php now it is working.
One more help i need is while uploading file if path not exists it will create directory automatically
Directory creation is not something the the
Upload
class will do I'm afraid. You'd need to use a custom upload action with your own function that would create the directory.Allan