예제 #1
0
 /**
  * Upload image
  * @param $for
  * @param $name
  * @param $id
  * @return bool|string
  */
 public function uploadImage($for, $name, $id)
 {
     $folder = $this->getUploadFolder() . $for . DIRECTORY_SEPARATOR . $id . '-';
     $finalName = "{$id}-";
     if (isset($_FILES[$name]) && file_exists($_FILES[$name]['tmp_name'])) {
         if (FileHelper::get()->isImage($_FILES[$name]['tmp_name'])) {
             $finalName .= $fname = trim(substr($_FILES[$name]['name'], -100));
             if (FileHelper::get()->upload($name, $folder . $fname)) {
                 return $finalName;
             }
             return false;
         } else {
             Messages::get()->error("Selected file isn't a image!");
             return false;
         }
     }
     return false;
 }
예제 #2
0
 /**
  * @return $this
  */
 public function updateImages()
 {
     $updates = false;
     foreach (["image_icon", "image_cover"] as $key) {
         if (!isset($_FILES[$key]) || !$_FILES[$key]['tmp_name']) {
             continue;
         }
         if (!FileHelper::get()->isImage($_FILES[$key]['tmp_name'])) {
             continue;
         }
         if (!file_exists($_FILES[$key]['tmp_name'])) {
             continue;
         }
         $name = $this->id . '_' . $key . substr($_FILES[$key]['name'], -50);
         if (FileHelper::get()->upload($key, dirname(APP_ROOT) . '/htdocs/' . BlogConfig::get()->articleImageLocation . $name)) {
             $old = $this->{$key};
             if ('default.png' != $old && $old != $name) {
                 @unlink(dirname(APP_ROOT) . '/htdocs/' . BlogConfig::get()->articleImageLocation . $old);
             }
             $this->{$key} = $name;
             $updates = true;
         }
     }
     if ($updates) {
         $this->save();
     }
     return $this;
 }
예제 #3
0
 public function changeIcon()
 {
     if (!isset($_FILES['icon']) || !$_FILES['icon']['tmp_name']) {
         return null;
     }
     if (!FileHelper::get()->isImage($_FILES['icon']['tmp_name'])) {
         return false;
     }
     if ($this->iconUploadHandle) {
         $function = $this->iconUploadHandle;
         return $function('icon');
     }
     $name = $this->user_id . substr($_FILES['icon']['name'], -30);
     FileHelper::get()->upload('icon', $this->getIconLocationPath() . $name);
     $column = Config::value('USER_ICON_COLUMN_NAME');
     $old = $this->user->{$column};
     if ($old && 'default.png' != $old && $name != $old) {
         @unlink($old);
     }
     $this->user->{$column} = $name;
     $this->user->save();
 }