Gra*_*ham 4 javascript php mysql jquery file-upload
我希望允许用户编写帖子并通过它(like a CMS blog post)内联上传图像.
编写文件上载脚本很容易.但是,允许"内置内置"按钮/功能被证明是棘手的.
有没有关于如何做到这一点的教程?
我正在搞乱一些JavaScript来允许它.另外,我不确定是否应该显示内联tmp图像或实际上传文件(with a separate upload button than the full form upload button)并在提交表单之前显示实际图像位置?我现在到处都是这个地方.
我该怎么办呢?
谢谢.
使用此Javascript代码:
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
添加此HTML:
<body>
<form id="form1" runat="server">
<input type='file' onchange="readURL(this);" />
<img id="blah" src="#" alt="your image" />
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
这是预览:http://jsbin.com/uboqu3/edit#javascript,html,live
我认为它可以帮到你.