我想使用Ajax上传/调整图像大小,然后将其显示在浏览器中而不是将其保存到文件中。我期待有一个形象,而不是我有一堆乱码。显示上传的图像
它可行吗?或者我不能也不需要诉诸其他的东西,比如保存到一个文件,然后走它的道路?或者也许使用画布?
谢谢你的时间。
HTML
<form enctype="multipart/form-data" action="file.php" method="Post" id="form">
<input type="file" name="user_image">
<input type="submit" value="Submit" name="submit">
</form>
<div id="blah"></div>
的Javascript
//using jquery-form.js
$('#form').on('submit', function(e) {
e.preventDefault();
$(this).ajaxSubmit({
target: '#blah',
success: function(){}
});
});
PHP
$img_width = imagesx($this->image);
$img_height = imagesy($this->image);
$image = imagecreatefromjpeg($_FILE['user_image']['tmp_name']);
$resized_image = imagecreatetruecolor(300, 300);
imagecopyresampled($resized_image, $image, 0, 0, 0, 0, 300, 300, $img_width, $img_height);
header('Content-Type:image/jpeg');
imagejpeg($resized_image);
以及回声'“
”;'在你的PHP文件 –
OP没有保存图像,这样映像路径无关 – Popnoodles