【问题标题】:How to upload image without using or by hiding <input type='file' />?如何在不使用或隐藏 <input type='file' /> 的情况下上传图片?
【发布时间】:2018-06-01 12:22:18
【问题描述】:

我正在制作一个 php 脚本,在该脚本中,我从目标本地计算机驱动器中获取目录和文件列表。

现在,我想要实现的是,当我点击列表中的特定图片名称时,它会上传到我的服务器。

我不想使用“浏览/输入类型='文件'”按钮选择图像。

我尝试了几种方法,但都没有成功。

请帮忙。

提前致谢。 H甘地

【问题讨论】:

  • 这意味着你想通过从本地机器上选择图片来上传图片到服务器。
  • 出于安全原因,您不能这样做。您只能上传用户选择的文件。
  • 你必须使用文件输入。如果您不想显示输入,可以将其隐藏。
  • @TarangP,shukshin.ivan,Nirali Joshi。谢谢大家的快速回复。建议如何隐藏 并同时为其设置值而不使用表单。

标签: php html ajax upload image-uploading


【解决方案1】:

$('button').click(function(){
    $('input').click();
});
input {
    display: block;
    visibility: hidden;
    width: 0;
    height: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" name="somename" size="chars">
<button>Choose File Button</button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    相关资源
    最近更新 更多