关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

php+html5兼容手机端的图片选取裁剪上传实例

发布时间:2020-03-09 00:00:00

网上大多图片上传插件都不带裁剪功能,这个是php+html5实现的兼容手机端的图片选取裁剪上传实例,分享出来希望能帮到大家。

首先放置一个上传按钮及相关预览信息等

 1 <form id="upload_form" enctype="multipart/form-data" method="post" action="upload.php" onsubmit="return checkForm()">   2     hidden crop params -->   3    <input type="hidden" id="x1" name="x1" autocomplete="off" />   4    <input type="hidden" id="y1" name="y1" autocomplete="off" />   5    <input type="hidden" id="x2" name="x2" autocomplete="off" />   6    <input type="hidden" id="y2" name="y2" autocomplete="off" />   7    <input type="file" name="image_file" id="image_file" onchange="fileSelectHandler()" />   8    <div class="error">  9     注意:上传前,先截图 
10    div>  11    <div class="step2">  12     <img id="preview" />  13     <div class="info">  14      <ul>  15       <li><label>文件大小label> <input type="text" id="filesize" name="filesize" class="input" autocomplete="off" />li>  16       <li><label>类型label> <input type="text" id="filetype" name="filetype" class="input" autocomplete="off" />li>  17       <li><label>图像尺寸label> <input type="text" id="filedim" name="filedim" class="input" autocomplete="off" />li>  18       <li><label>宽度label> <input type="text" id="w" name="w" class="input" autocomplete="off" />li>  19       <li><label>高度label> <input type="text" id="h" name="h" class="input" autocomplete="off" />li>  20      ul>  21     div>  22     <input type="submit" value="上传" class="btn" />  23    div>  24 form>

 

接着引用js和css样式

1 <link href="css/jquery.Jcrop.min.css" rel="stylesheet" type="text/css" /> 2 <script type="text/javascript" src="jquery.js">script>  3 <script src="js/jquery.Jcrop.min.js">script>

 

接着看下表单的检查

1 function checkForm() { 
2     if (parseInt($('#w').val())) //若是没有截屏 3         return true; 
4     $('.error').html('请先选择图片,并且截图').show(); 
5     return false; 
6 }

 

上传文件条件设置

 1 var rFilter = /^(image\/jpeg|image\/png|image\/jpg)$/i; 
 2 if (!rFilter.test(oFile.type)) { 
 3     $('.error').html('请选择jpg、jpeg或png格式的图片').show(); 
 4     return; 
 5 } 
 6   7 // check for file size  8 if (oFile.size > 1000 * 1024) { 
 9     $('.error').html('请上传小于1M的图片').show(); 
10     return; 
11 }

 

本文转自:https://www.sucaihuo.com/php/71.html 转载请注明出处!


/template/Home/Zkeys/PC/Static