我做了搜索,但我找不到答案。
我想要导入按钮,用户将从用户计算机导入文本文件,文本文件的数据应该在textarea中可见。
我有这个代码在textarea中显示但不知道如何从用户计算机中选择和获取数据。
/**
*
* Adjust option_selection.js labels based on variant default values
*
*/
Slate.simplifyVariantLabels = function (product) {
// option_selection.js does not add a label if there is only one variant option.
// Add one as long as it is not 'Title' (Shopify's default), add one.
if (product.options.length === 1 && product.options[0] !== 'Title') {
$('.selector-wrapper:eq(0)').prepend('<label for="ProductSelect-option-0">'+ product.options[0] +'</label>');
}
// Hide variant dropdown if only one exists and title contains 'Default'
if (product.variants.length && product.variants[0].title.indexOf('Default') >= 0) {
$('.selector-wrapper').hide();
}
};
提前致谢。
P.S。该文件不应保存在服务器上,而只是获取数据并显示在textarea中。
答案 0 :(得分:0)
你应该使用
<input type="file" name="userfile">
然后将其发送到服务器。您将能够通过全局变量$ _FILES:
获取文件路径$data = file_get_contents($_FILES['userfile']['tmp_name']);
echo '<textarea>' . htmlspecialchars($data). '</textarea>';
然后将其粘贴到textarea中。但不要忘记验证用户文件(大小,扩展等)