linux 上传图片路径,图片上传(和linux 兼容)

gistfile1.txt

//图片保存 和弹框框架配合

$('#imgSave').on('click', function () {

$('.update-store-form .upload-msg').html("");

if ($('#upload-file').val()) {

layer.open({

content: '您确认保存吗?',

btn: ['确认', '取消'],

shadeClose: true,

yes: function () {

layer.open({

content: '确认', time: 1, success: function (layero, index) {

comitUpdateShop(); //调用函数头像上传

tag = "你修改了头像"

$('#imgSave').removeAttr("disabled");

}

});

}, no: function () {

layer.open({content: '您选择了取消', time: 1});

}

});

} else {

showTip("请选择图片");

}

});

//函数图片上传

var comitUpdateShop = function () {

var target = $('.update-store-form .upload-msg');

if ($('#upload-file').val()) {

var formData = new FormData($("#fileForm")[0], $("#shopId").val());

$("#imgSave").attr("disabled", true);//防表单提交

$.ajax({

url: 'shop/shopSrc',

type: "post",

data: formData,

processData: false,

contentType: false,

success: function (data, status) {

if (data == 0) {

target.html('*' + data.desc);

} else {

target.html('*' + data.desc);

}

},

error: function () {

target.html('* 保存失败,请重新上传!');

}

});

} else {

target.html('* 保存失败,请重新上传!');

}

$('#upload-file').val('');

target.addClass('show');

}

html代码选择图片

仅支持JPG图片,且文件小于1M,尺寸

为200*200像素,请确认是否清晰。

p-dnjtecac-k.html

%7B%7Bshop.imgSrc%7D%7D

* 保存成功!

保存

java后台代码///

@PostMapping(value = "shop/shopSrc")

public ResponseMsg fildUpload(@RequestParam(value = "fileName", required = false) MultipartFile file,

@RequestParam(value = "shopid", required = false) String shopid,

HttpServletRequest request) throws IllegalStateException, IOException {

if (file != null) {// 判断上传的文件是否为空

String path = null;// 文件路径

String type = null;// 文件类型

String fileName = file.getOriginalFilename();// 文件原名称

if (file.getSize() >= 1024000) return new ResponseMsg(-1, null, "图片超过1M");

System.out.println("上传的文件原名称:" + fileName);

type = fileName.indexOf(".") != -1 ? fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()) : null;

if (type != null) {// 判断文件类型是否为空

if ("GIF".equals(type.toUpperCase()) || "PNG".equals(type.toUpperCase()) || "JPG".equals(type.toUpperCase())) {

// 项目在容器中实际发布运行的根路径

// String realPath = request.getClass().getResource("/").getFile().toString();

String root = "";

if (System.getProperty("os.name").toLowerCase().startsWith("win")) {

root = "d:";

}

String realPath = root + Constance.UPLOAD_PATH + "img" + System.getProperty("file.separator");//request.getClass().getResource("/").getFile().toString();

File tmp = new File(realPath);

if (!tmp.exists()) {

tmp.mkdirs();

}

// 自定义的文件名称

// String trueFileName = String.valueOf(System.currentTimeMillis())+"." + type;

String trueFileName = UUID.randomUUID().toString()+"." + type;

// 设置存放图片文件的路径

//path=realPath+System.getProperty("file.separator")+trueFileName;

// path="/static/img/"+trueFileName;

// path = System.getProperty("file.separator") + "static" + System.getProperty("file.separator") + "img" + System.getProperty("file.separator") + trueFileName;

System.out.println("存放图片文件的路径:" + realPath + trueFileName);

// 转存文件到指定的路径

file.transferTo(new File(realPath + trueFileName));

// String savePath = System.getProperty("file.separator") + "img" + System.getProperty("file.separator") + trueFileName;

// String savePath = "/upload/" + "img" + System.getProperty("file.separator") + trueFileName;

String savePath = "/upload/" + "img" + "/" + trueFileName;

shopService.updateShopImgSrc(shopid, savePath);

System.out.println("文件成功上传到指定目录下" + savePath);

return new ResponseMsg(0, "图片保存成功");

} else {

return new ResponseMsg(-1, "图片后辍名错误");

}

}

} else {

return new ResponseMsg(-1, "图片不存在");

}

return null;

}

///代码用到的类和变量 /

public final class Constance {

public static final String UPLOAD_PATH = "/home/cma/custWifi/upload/";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用ZXing.ImageSharp.V2组件生成二维码图片,并在图片上包含二维码和提示文字时,并且要求兼容Linux系统,你可以按照以下步骤进行操作: 首先,确保你的项目中已安装了ZXing.Net库和ImageSharp库,可以通过NuGet包管理器进行安装。 接下来,你可以使用以下代码方法来生成带有二维码和提示文字的图片: ```csharp using System; using System.IO; using System.Text; using SixLabors.Fonts; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using ZXing; using ZXing.Common; public class QrCodeGenerator { public static void GenerateQrCodeWithText(string content, string text, string outputPath) { // 生成二维码 BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Width = 300, Height = 300 } }; using (var qrCodeImage = writer.Write(content)) { // 加载字体 var fontCollection = new FontCollection(); var font = fontCollection.Install("path/to/your/font.ttf"); // 创建画布 var image = new Image<Rgba32>(500, 500); image.Mutate(ctx => { ctx.Fill(Rgba32.White); ctx.DrawImage(qrCodeImage, new Point(100, 100), 1f); ctx.DrawText(new TextGraphicsOptions { TextOptions = new TextOptions { FontSize = 24, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, ApplyKerning = true }, WrapTextWidth = 300 }, text, font, Rgba32.Black, new PointF(250, 400)); }); // 保存图片 image.Save(outputPath); } } } ``` 在上述代码中,你需要将`"path/to/your/font.ttf"`替换为你自己的字体文件路径。此外,你可以根据需要调整二维码的大小、文字的大小和位置等参数。 最后,调用该方法并传入相应的参数即可生成带有二维码和提示文字的图片: ```csharp string content = "Your content here"; string text = "Your text here"; string outputPath = "path/to/output/image.png"; QrCodeGenerator.GenerateQrCodeWithText(content, text, outputPath); ``` 请注意,该方法需要在支持ImageSharp和ZXing.Net的环境中运行,因此确保已将这些库安装到你的项目中,并引入相关命名空间。 希望以上代码能满足你的需求,如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值