public function saveFile($file, $dir = '', $name = null) { // normal $_FILES if (is_array($file)) { $filename = $file['name']; $put_file = $this->getPutFilename($dir, $filename); $extension = fx::path()->fileExtension($put_file); if (!$extension || !in_array($extension, $this->allowed_extensions)) { return; } $full_path = fx::path('@files/' . $dir . '/' . $put_file); $this->mkdir(fx::path('@files/' . $dir)); $res = move_uploaded_file($file['tmp_name'], $full_path); if (!$res) { return; } } else { if (is_string($file)) { $full_path = $this->saveRemoteFile($file, $dir, $name); if (!$full_path) { return; } } } // default image resizer $resize_config = fx::config('image.default_resize'); if ($this->isImage($full_path) && $resize_config) { $thumb = new \Floxim\Floxim\System\Thumb($full_path, $resize_config); $thumb->process($full_path); } $result = $this->getInfo($full_path); return $result; }
public function saveFile($file, $dir = '', $name = null) { // normal $_FILES if (is_array($file)) { $filename = $file['name']; $put_file = $this->getPutFilename($dir, $filename); $full_path = fx::path('@files/' . $dir . '/' . $put_file); $this->mkdir(fx::path('@files/' . $dir)); $res = move_uploaded_file($file['tmp_name'], $full_path); if (!$res) { return; } } else { if (is_string($file)) { $full_path = $this->saveRemoteFile($file, $dir, $name); if (!$full_path) { return; } } } $result = array('filename' => fx::path()->fileName($full_path), 'fullpath' => $full_path, 'size' => $this->readableSize(filesize($full_path))); // default image resizer $resize_config = fx::config('image.default_resize'); if ($this->isImage($full_path)) { $thumb = new \Floxim\Floxim\System\Thumb($full_path, $resize_config); $img_info = $thumb->getInfo(); $result['is_image'] = true; if ($img_info && isset($img_info['width']) && isset($img_info['height'])) { $result['width'] = $img_info['width']; $result['height'] = $img_info['height']; } if ($resize_config) { $thumb->process($full_path); } } $http_path = fx::path()->http($full_path); $result['path'] = $http_path; return $result; }