Pass variable while inserting in to database

Pass variable while inserting in to database

lavanialavania Posts: 10Questions: 4Answers: 0

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

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406

    To be honest I don't know what those asterisks in this line mean:

    **'img_type'    => 'WSQA',**
    

    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

    'img_type'    => 'WSQA',
    

    I use this code - and it works perfectly fine:

    ->db( 'file', 'id', array(
        'soft_deleted'  => 0, 
        'about'         => 'Z',  //contract management
        'name'          => Upload::DB_FILE_NAME,
        'size'          => Upload::DB_FILE_SIZE,
        'web_path'      => Upload::DB_WEB_PATH,
        'system_path'   => Upload::DB_SYSTEM_PATH,
        'creator_id'    => $_SESSION['orig_id']
    ) )
    
  • lavanialavania Posts: 10Questions: 4Answers: 0
    edited March 24

    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

        ) )
    
        ->validator( Validate::fileSize( 3000000, 'Files must be smaller that 3MB' ) )
        ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
    ),      
    

    and it is not working it is not putting 'WSQA' in img_type field of DB

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    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

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406

    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.

  • lavanialavania Posts: 10Questions: 4Answers: 0

    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

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    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

Sign In or Register to comment.