缩小图像尺寸 - 输入类型="文件"

时间:2015-09-04 12:37:07

标签: javascript php html forms file-upload

我会在用户上传时缩小图片尺寸。第一页上的图像预览需要显示的javascript。因此,用户可以在第一页(upload.php)

期间更改图像

upload.php的



function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
          
            reader.onload = function (e) 
			{
                $('#preview').attr('src', e.target.result);
			}
            
            reader.readAsDataURL(input.files[0]);
        }
    }
    
    $("#imgPrev").change(function(){
        readURL(this);
    });

    <form action="/2nd-page.php" method="post" enctype="multipart/form-data">
    <div class="upload">
    <span class="btn btn-default btn-file">
    <input type="file" name="imgPrev" id="imgPrev" accept="image/jpg,image/gif">
    </span>
    </div>
    <div class="div-preview">
    <img name="preview" id="preview" style="max-width:360px;" height="100%" src="#" class="img-rounded" alt="">
    </div>
    </form>
&#13;
&#13;
&#13;

第二-page.php文件

&#13;
&#13;
		if(!empty($_FILES["imgPrev"]["name"])) 
		{
			//Upload new Image in Directory
			$temp = explode(".", $_FILES["imgPrev"]["name"]);
			$filename = round(microtime(true)) . '.' . end($temp);
			//$_SESSION['tmp_filename'] = $filename;
			move_uploaded_file($_FILES["imgPrev"]["tmp_name"],$dir.'/'.$filename);
		}
&#13;
&#13;
&#13;

从用户上传时是否有可能缩小图像尺寸?问题是,当用户上传巨大的图像时,第二页.php需要很长时间才能加载。 :-(

感谢你的支持。

电贺, Yab86

0 个答案:

没有答案