dsf23223 2019-03-09 07:57
浏览 40

在服务器上上传图像的问题

i am trying to upload an image to the localhost server, but the file is not uploading.when i click on 'upload the image' it does not show anything, i searched a lot about it but i don't know where the problem is.

here is my code

<label id="file1">Upload image
<input onchange="readurl2()" id="input" type="file" name="image" size="60" required>
</label>
<br>
<img id="blah" src="..\images\avatar.png" alt="avatar">

js function

function readurl2() 
{
    input=document.getElementById('input');
    if (input.files && input.files[0]) 
    {
        var reader = new FileReader();
        reader.onload = function (e) 
        {
            document.getElementById('blah').src=e.target.result;
        };
        reader.readAsDataURL(input.files[0]);
        return "done";
    }
}

please help me.!!

  • 写回答

1条回答 默认 最新

  • dou31797719 2019-03-09 08:03
    关注

    FileReader Object reads the file on the front-end, but not uploading your file by itself.

    one option to upload you got, is to submit the form and this form should have property: enctype="multipart/form-data"

    read there

    another option (somehow more advanced) is to post the file in base64 text via ajax request.

    Or you may use a library like axios to submit the form as multipart form with the row content of your file input.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程