有没有人知道如何进行简单的图像上传并在页面上显示它.
这就是我要找的东西.
<img src>会做,因为我需要显示不同的图像大小.这是我的代码.(其中一些是编辑的,我从这里得到它)
<style>
/* Image Designing Propoerties */
.thumb {
height: 75px;
border: 1px solid #000;
margin: 10px 5px 0 0;
}
</style>
<script type="text/javascript">
/* The uploader form */
$(function () {
$(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
$('#myImg').attr('src', e.target.result);
$('#yourImage').attr('src', e.target.result);
};
</script>
<input type='file' />
</br><img id="myImg" src="#" alt="your image" height=200 …Run Code Online (Sandbox Code Playgroud) 当我尝试运行PHP MySQL脚本时遇到此问题.当我尝试运行我的.php文件时,这就是我得到的.
mysql_connect(): No connection could be made because the target machine actively refused it
Run Code Online (Sandbox Code Playgroud)
这是dbconnect.php的代码:
<?php
mysql_connect("localhost","root");
mysql_select_db("users");
?>
Run Code Online (Sandbox Code Playgroud)
我之前尝试过使用这种格式,但我不知道这段代码有什么问题.
先感谢您.
我想选择一个文件并在浏览器中显示图像。我尝试插入直接图像路径,它起作用了。
现在的问题是,如何显示图像<input type=file>?
这是我的代码:
function myFunction() {
var file = document.getElementById('file').files[0];
var reader = new FileReader();
reader.onloadend = function {
var image = document.createElement("img");
image.src = "reader"
image.height = 200;
image.width = 200;
document.body.appendChild(image);
}
}
Run Code Online (Sandbox Code Playgroud)
<input type=file name=filename id=file>
<button type=button onclick='myFunction()'>Display</button>
Run Code Online (Sandbox Code Playgroud)