上傳檔案點擊後顯示圖片

來源:互聯網
上載者:User

標籤:script   strong   open   upload   substr   substring   inf   demo   pre   

HTML代碼

 

<include file="./Application/Home/View/default/Public/homeheader.html" /><html><body><!--<form action="{:U(‘home/statistics/uploadinformation‘)}" method="post" enctype="multipart/form-data">    <label for="file">Filename:</label>    <input type="file" name="file" id="file"/>    <br />    <input type="submit" name="submit" value="上傳" /></form>!--><form action="{:U(‘home/setting/upload‘)}" method="post" enctype="multipart/form-data">    <div style="width: 100%;height: 100%;">        <div><strong>代理資訊上傳:</strong></div>        <div class="form-group">            <a class="button input-file" style="text-align: center;vertical-align: middle;" href="javascript:void(0);">上傳合約檔案<input  size="80" type="file" name="file1" id="file1" onchange="check1()" /></a><!--//顯示合約!-->            <a class="button input-file" style="text-align: center;vertical-align: middle;" href="javascript:void(0);">上傳證件圖片<input  size="80" type="file" name="file2" id="file2" onchange="check2()" /></a><!--//顯示證件!-->            <button class="button bg-main" type="submit" name="submit" style="text-align: center;vertical-align: middle;" >確定上傳</button>        </div>        <div><p id="f1name"></p></div>        <div><p id="f2name"></p></div>        <br>        <a id="changemouse1" class="dialogs" data-toggle="click" data-target="#mydialog1" data-width="40%" onmouseover="changemouse()" onmouseout="defaultmouse()">查看合約</a><br>        <a id="changemouse2" class="dialogs" data-toggle="click" data-target="#mydialog2" data-width="40%" onmouseover="changemouse()" onmouseout="defaultmouse()">查看證件</a>    </div></form><div id="mydialog1"><!--點擊時快顯視窗,顯示合約圖片!-->    <div class="dialog">        <div class="dialog-head">            <span class="close rotate-hover"></span><strong>查看合約</strong>        </div>        <div style="text-align: center;vertical-align: middle" class="dialog-body"><img style="height:70%" width="100%" src="{$addr1}"></div>        <div class="dialog-foot">            <button class="button bg-green dialog-close">確認</button>        </div>    </div></div><div id="mydialog2"><!--點擊時快顯視窗,顯示合證件圖片!-->    <div class="dialog">        <div class="dialog-head">            <span class="close rotate-hover"></span><strong>查看證件</strong>        </div>        <div style="text-align: center;vertical-align: middle" class="dialog-body"><img style="height:70%" width="100%" src="{$addr2}"></div>        <div class="dialog-foot">            <button class="button bg-green dialog-close">確認</button>        </div>    </div></div><script>    function changemouse() //滑鼠移過去變成手形    {        var obj1 = document.getElementById("changemouse1");        var obj2 = document.getElementById("changemouse2");        obj1.style.cursor = ‘pointer‘;        obj2.style.cursor = ‘pointer‘;    }</script><script>    function defaultmouse()//滑鼠移回,回複預設    {        var obj1 = document.getElementById("changemouse1");        var obj2 = document.getElementById("changemouse2");        obj1.style.cursor = ‘default‘;        obj2.style.cursor = ‘default‘;    }</script><!--<script>    function display()    {        var obj = document.getElementById("demo")        {            obj.style.display="";        }    }</script>!--><script>    function check1()//檢查圖片格式    {        var filepath=file1.value ;        filepath=filepath.substring(filepath.lastIndexOf(‘.‘)+1,filepath.length);        if(filepath != ‘jpg‘ && filepath != ‘gif‘&& filepath != ‘png‘&& filepath != ‘jpeg‘)            alert("只能上傳JPG,GIF,PNG或者JPEG格式的圖片");        else document.getElementById("f1name").innerText=file1.value;    }</script><script>    function check2()    {        var filepath=file2.value ;        filepath=filepath.substring(filepath.lastIndexOf(‘.‘)+1,filepath.length);        if(filepath != ‘jpg‘ && filepath != ‘gif‘&& filepath != ‘png‘&& filepath != ‘jpeg‘)            alert("只能上傳JPG,GIF,PNG或者JPEG格式的圖片");       else document.getElementById("f2name").innerText=file2.value;    }</script></body></html>

 

 

PHP代碼

 

public function upload(){    if (isset($_POST[‘submit‘]))    {        import(‘Think.Verify.Upload‘);        // $imagea = new Image();        $picture = new Upload() ; // 執行個體化上傳類        $picture->maxSize = 3145728;// 設定附件上傳大小        $picture->exts = array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘);// 設定附件上傳類型        $picture->rootPath = ‘./Uploads/‘;// 設定附件上傳根目錄        $picture->savepath = ‘‘; // 設定附件上傳(子)目錄        $info = $picture->upload();// 上傳檔案        if(!($info[‘file1‘]&&$info[‘file2‘]))        {            echo "<script>alert(‘請上傳檔案‘)</script>";        }        // $fr = ‘./Uploads/‘; //錯誤http://localhost/use/index.php/home/user/Uploads/2016-11-14/5829803394673.jpg        // $fr = ‘Uploads/‘; //錯誤http://localhost/use/index.php/home/user/Uploads/2016-11-14/582980519743a.jpg        // $fr = ‘/Uploads/‘; //錯誤http://localhost/Uploads/2016-11-14/5829807535c04.jpg        $fr = ‘/user/Uploads/‘;//正確 http://localhost/user/Uploads/2016-11-14/582963ff2640f.jpg        // $addr1 = $fr . $info[‘file1‘][‘savepath‘] . $info[‘file1‘][‘savename‘];        // $addr2 = $fr . $info[‘file2‘][‘savepath‘] . $info[‘file2‘][‘savename‘];        $user = M(‘user_admin‘);// 執行個體化User對象        // 更改使用者的certificate_address和contract_address的值        $upload_role_id_address = array(‘certificate_address‘ => $fr.$info[‘file2‘][‘savepath‘].$info[‘file2‘][‘savename‘], ‘contract_address‘ => $fr.$info[‘file1‘][‘savepath‘].$info[‘file1‘][‘savename‘]);        $name = $_SESSION[‘adminid‘];//擷取SESSION的賬戶名 $_SESSION[‘adminid‘],$_SESSION[‘pwd‘],$_SESSION[‘loginkey‘],        $where[‘admin‘] = $name;//判斷條件執行個體化        $user->where($where)->setField($upload_role_id_address);        // $addr1 = $upload_role_id_address[‘contract_address‘];        // $addr2 = $upload_role_id_address[‘certificate_address‘];        // $this->assign(‘addr1‘,$addr1);        // $this->assign(‘addr2‘,$addr2);        //echo "<img src=‘$addr1‘>";die();        $image1 = new \Think\Image();        $image2 = new \Think\Image();        $image1->open(‘./Uploads/‘.$info[‘file1‘][‘savepath‘].$info[‘file1‘][‘savename‘]);        $image2->open(‘./Uploads/‘.$info[‘file2‘][‘savepath‘].$info[‘file2‘][‘savename‘]);        $image1->thumb(800, 600,\Think\Image::IMAGE_THUMB_FIXED)->save(‘./Uploads/contract.jpg‘);//固定縮圖        $image2->thumb(800, 600,\Think\Image::IMAGE_THUMB_FIXED)->save(‘./Uploads/certificate.jpg‘);//固定縮圖        // $image1->thumb(150, 150)->save(‘./Uploads/contract.jpg‘); //按比例縮放        // $image2->thumb(150, 150)->save(‘./Uploads/certificate.jpg‘);        echo "<script>alert(‘資訊上傳成功‘)</script>";        $addr1= $fr.‘contract.jpg‘;        $addr2= $fr.‘certificate.jpg‘;        /*   echo " <div class=\"form-group\" style=\"float: right\">//檔案預覽功能           <div><strong>檔案預覽:</strong></div>           <table>               <tr>                   <td><img src=‘$addr1‘></td>                   <td><img src=‘$addr2‘></td>               </tr>           </table>        </div>";//顯示合約        */        //echo "<img src=‘$addr2‘>";//顯示證件        $this->assign(‘addr1‘,$addr1);        $this->assign(‘addr2‘,$addr2);    }    $this->display();} //修改

另外在當前檔案夾建立個Upload檔案夾,不然沒法上傳圖片。

 

http://blog.csdn.net/s371795639/article/details/53410697

上傳檔案點擊後顯示圖片

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.