Save file in database with QFileasset

thread: 3 messages  |  last: about 2 years ago  |  started: thursday, january 7, 2010, 2:33 pm pst


#1  |  UyCaRumBa (Trujillo) Peru
Thursday, January 7, 2010, 2:33 PM PST

Hello everybody there...

Well i would like to know if anybody have had experience dealing with blob fields in mysql, i´m trying to save the content of an image into a blob data type and qcodo does not work with that, when i try to save the content using QFileAsset all seems to go ok but when i see the blob column in the record that shows null.
i will apreciate any help
greetings!

#2  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Friday, January 8, 2010, 9:18 AM PST

You would need to manually enter in the data into the blob field by doing something like:

   // Assume we have the following declared
   protected $objMyTable;
   protected $flaFileAsset;

   $strBlobData = file_get_contents($this->flaFileAsset->File);
   $objMyTable->BlobField = $strBlobData;
   $objMyTable->Save();

(note that the above hasn't really been tested, but hopefully this will give you an idea of how to proceed)

#3  |  UyCaRumBa (Trujillo) Peru
Tuesday, January 19, 2010, 9:17 AM PST

Hi Mike, thanks for your help, here hit my code, which is finally well.



    // Controls for Archive's Data Fields

    protected $txtImg;

protected function btnSave_Click($strFormId, $strControlId, $strParameter) {

    copy($this->txtImg->File, '/tmp'. $this->txtImg->FileName)        
    $strArchiveData = file_get_contents($this->txtImg->File);
    $this->mctArchive->Archive->Img = $strArchiveData;
    
    
    $this->mctArchive->SaveArchive();
    $this->RedirectToListPage();

}
.bc


Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.