/** * 验证上传文件的类型是否为图片及大小是否越界 * * @param * $file * @param int $max_file_size * * @return bool string */ public static function validateUpload($file, $max_file_size = 0) { if ((int) $max_file_size > 0 && $file['size'] > (int) $max_file_size) { return sprintf(Util_Tools::displayError('Image is too large (%1$d kB). Maximum allowed: %2$d kB'), $file['size'] / 1024, $max_file_size / 1024); } if (!self::isRealImage($file['tmp_name'], $file['type']) || !self::isCorrectImageFileExt($file['name'])) { return 'Image format not recognized, allowed formats are: .gif, .jpg, .png'; } if ($file['error']) { return sprintf(Util_Tools::displayError('Error while uploading image; please change your server\'s settings. (Error code: %s)'), $file['error']); } return true; }
function download($remote_path, $file, $replace = true, $mode = 'auto') { if ($this->is_connected && !empty($remote_path)) { if ($mode == 'auto') { $mode = $this->_settype(Util_Tools::getFileExtension($remote_path)); } $mode = $mode == 'ascii' ? FTP_ASCII : FTP_BINARY; if (file_exists($file) && $replace) { unlink($file); } if (@ftp_get($this->conn, $file, $remote_path, $mode)) { return true; } else { if ($this->debug) { die(Util_Tools::displayError('FTP获取文件失败:' . $remote_path . ':' . $file)); } } } else { if ($this->debug) { die(Util_Tools::displayError('FTP未连接或目录为空:' . $remote_path)); } } return false; }