Example #1
0
 public function getAvatar()
 {
     $pic = new \Towel\Model\Pic();
     $pics = $pic->findObjectPics($this->table, $this->getId())->fetchAll();
     if (count($pics) > 0) {
         $the_pic = array_shift($pics);
         return '/uploads/' . $the_pic['pic'];
     } else {
         return false;
     }
 }
Example #2
0
 /**
  * It will attach the file.
  *
  * @param $id
  * @param $table
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  */
 public function attachFile($id, $table, \Symfony\Component\HttpFoundation\File\UploadedFile $file)
 {
     $newFileName = md5(microtime() . '.' . strtolower($file->getClientOriginalExtension()));
     $relativePath = $table . '/' . date('Y/m/d');
     $relativeFilePath = $relativePath . '/' . $newFileName;
     $dstPath = APP_UPLOADS_DIR . '/' . $relativePath;
     $file->move($dstPath, $newFileName);
     $pic = new \Towel\Model\Pic();
     $pic->object_id = $id;
     $pic->object_type = $table;
     $pic->pic = $relativeFilePath;
     $pic->created = time();
     $pic->save();
 }