Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有文本输入字段的文件上载,用户也可以输入文件路径_Javascript_Jquery - Fatal编程技术网

Javascript 带有文本输入字段的文件上载,用户也可以输入文件路径

Javascript 带有文本输入字段的文件上载,用户也可以输入文件路径,javascript,jquery,Javascript,Jquery,我目前有一个表单,其中上载文件如下所示: 我想让它看起来像这样: 这样做的原因是服务器已经有了这些文件。因此,我只想在输入字段中添加URL。然而,上传按钮也很重要,因为我们需要上传服务器中还没有的文件 我们最好怎么做 我目前有以下代码: function wp_custom_attachment() { wp_nonce_field(plugin_basename(__FILE__), 'wp_custom_attachment_nonce'); $html .= '<

我目前有一个表单,其中上载文件如下所示:

我想让它看起来像这样:

这样做的原因是服务器已经有了这些文件。因此,我只想在输入字段中添加URL。然而,上传按钮也很重要,因为我们需要上传服务器中还没有的文件

我们最好怎么做

我目前有以下代码:

function wp_custom_attachment() {
    wp_nonce_field(plugin_basename(__FILE__), 'wp_custom_attachment_nonce');
    $html .= '<input type="file" id="wp_custom_attachment" name="wp_custom_attachment" value="" size="25" />';
    echo $html;
}

您可以使用
type='file'
的隐藏输入,以及
按钮
type='text'
的输入来完成此操作。为了激活按钮,我们在按钮的
onclick
处添加了一个触发器
onchange
type='file'
我们触发一个函数
changeInput
来更改输入的内容
type='text'

这将导致以下
html

打开
函数changeInput(){
document.getElementById(“文件名”).value=document.getElementById(“文件”).value;
}

用户不能写任何路径,这仅仅是出于安全考虑。我想你必须重新考虑你的应用程序逻辑。这只是管理面板。为了方便起见。你信任每一个可以登录到你的管理面板的用户吗?希望你不会。管理员只是我和我的同事。为什么你不能上传文件,然后在文件名后面生成一个随机散列呢。这样,您就不会遇到文件名相同的问题。我已经解决了它,但这样更好。非常感谢你。接受它:)
$html .= '<input type="text" value="" id="wp_custom_attachment" name="wp_custom_attachment" onclick="javascript:document.getElementById(\'file\').click();"><input id="file" type="file" name="img" onchange="ChangeText(this, \'wp_custom_attachment\');"/>';
Warning: Illegal string offset 'url' in /path/content.php on line 42