PHP+jQuery+html5实现文章缩略图裁剪

文章目录
  • 载入必要的JS、CSS文件
  • HTML部分
  • jQuery部分检查表单
  • 上传条件初始化和配置
  • 缩略图裁剪效果截图:

    511遇见

    载入必要的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>

    HTML部分

    1. <form id="upload_form" enctype="multipart/form-data" method="post" action="upload.php" onsubmit="return checkForm()">  
    2.  
    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>

    jQuery部分检查表单

    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. }

    百度云盘源码下载:http://pan.baidu.com/s/1pLgtNon


    发布日期:

    所属分类: JavaScript/jquery 标签:   


    没有相关文章!