68399皇家赌场
  • 集成介绍
  • 最新解决方案
  • 呼叫中心培训课程
  • 集成经验
  • PHP无刷新上传文件实现代码,利用iframe实现无刷

    来源:http://www.ccidsi.com 作者:呼叫中心培训课程 人气:199 发布时间:2019-08-21
    摘要:复制代码 代码如下: index.html html head title无刷新上传文件/title meta Content-type="text/html" charset="utf-8" / scripttype="text/网页特效" function startUpload() { document.getElementById('processing').innerHTML = 'lodi

    复制代码 代码如下:

    index.html

    <html>
    <head>
    <title>无刷新上传文件</title>
    <meta Content-type="text/html" charset="utf-8" />
    <script type="text/网页特效">
    function startUpload() {
    document.getElementById('processing').innerHTML = 'loding...';
    return true;
    }
    function stopUpload(rel){
    var msg;
    switch (rel) {
    case 0:
    msg = "上传成功";
    break;
    case 1:
    msg = "上传的文件超越限定";
    break;
    case 2:
    msg = "只可以上传图片文件";
    break;
    default:
    msg = "上传文件战败";
    }
    document.getElementById('processing').innerHTML = msg;
    }
    </script>
    </head>
    <body>
    <div style="text-align:center">
    <div id="processing"></div>
    <form action="upload.php教程" method="post" enctype="multipart/form-data" target="form-target" onsubmit="startUpload();">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <input type="file" name="myfile" />
    <input type="submit" name="sub" value="upload" />
    </form>
    <iframe style="width:0; height:0; border:0;" name="form-target"></iframe>
    </div>
    </body>
    </html>

    <html>
      <head>
      <title>无刷新上传文件</title>
      <meta Content-type="text/html" charset="utf-8" />
      <script type="text/网页特效">
      function startUpload() {
      document.getElementById('processing').innerHTML = 'loding...';
      return true;
      }
      function stopUpload(rel){
      var msg;
      switch (rel) {
      case 0:
      msg = "上传成功";
      break;
      case 1:
      msg = "上传的公文超越限制";
      break;
      case 2:
      msg = "只好上传图片文件";
      break;
      default:
      msg = "上传文件失利";
      }
      document.getElementById('processing').innerHTML = msg;
      }
      </script>
      </head>
      <body>
      <div style="text-align:center">
      <div id="processing"></div>
      <form action="upload.php教程" method="post" enctype="multipart/form-data" target="form-target" onsubmit="startUpload();">
      <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
      <input type="file" name="myfile" />
      <input type="submit" name="sub" value="upload" />
      </form>
      <iframe style="width:0; height:0; border:0;" name="form-target"></iframe>
      </div>
      </body>
      </html>
      php代码
      <?php
      sleep(2);
      $fileTypes = array('jpg','png','gif','bmp');
      $result = null;
      $uploadDir = './upfiles';
      $maxSize = 1 * pow(2,20);
      if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['sub'])) {
      $myfile = $_FILES['myfile'];
      $myfileType = substr($myfile['name'], strrpos($myfile['name'], ".") 1);
      if ($myfile['size'] > $maxSize) {
      $result = 1;
      } else if (!in_array($myfileType, $fileTypes)) {
      $result = 2;
      } elseif (is_uploaded_file($myfile['tmp_name'])) {
      $toFile = $uploadDir . '/' . $myfile['name'];
      if (@move_uploaded_file($myfile['tmp_name'], $toFile)) {
      $result = 0;
      } else {
      $result = -1;
      }
      } else {
      $result = 1;
      }
      }
      ?>
      <script type="text/javascript">
      window.top.window.stopUpload(<?php echo $result; ?>);
      </script>

    复制代码 代码如下:

    php代码

    你或然感兴趣的文章:

    • php ajax无刷新上传图片的落实格局
    • PHP Ajax达成无刷新附件上传
    • php html5落到实处无刷新图片上传教程
    • php ajax无刷新上传图片实例代码
    • ThinkPHP结合AjaxFileUploader完成无刷新文件上传的艺术
    • 采用PHP和HTML5 FormData完毕无刷新文件上传教程
    • php iframe达成掩饰无刷新上传文件
    • PHP无刷新上传文件贯彻代码
    • php ajax无刷新上传图片实例代码
    • PHP JavaScript实现无刷新上传图片
    • php使用Iframe无刷新上传的代码

    <html>
    <head>
    <title>无刷新上传文件</title>
    <meta Content-type="text/html" charset="utf-8" />
    <script type="text/javascript">
    function startUpload() {
    document.getElementById('processing').innerHTML = 'loding...';
    return true;
    }
    function stopUpload(rel){
    var msg;
    switch (rel) {
    case 0:
    msg = "上传成功";
    break;
    case 1:
    msg = "上传的文书超越限定";
    break;
    case 2:
    msg = "只可以上传图片文件";
    break;
    default:
    msg = "上传文件失利";
    }
    document.getElementById('processing').innerHTML = msg;
    }
    </script>
    </head>
    <body>
    <div style="text-align:center">
    <div id="processing"></div>
    <form action="upload.php" method="post" enctype="multipart/form-data" target="form-target" onsubmit="startUpload();">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <input type="file" name="myfile" />
    <input type="submit" name="sub" value="upload" />
    </form>
    <iframe style="width:0; height:0; border:0;" name="form-target"></iframe>
    </div>
    </body>
    </html>

    <?php
    sleep(2);
    $fileTypes = array('jpg','png','gif','bmp');
    $result = null;
    $uploadDir = './upfiles';
    $maxSize = 1 * pow(2,20);
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['sub'])) {
    $myfile = $_FILES['myfile'];
    $myfileType = substr($myfile['name'], strrpos($myfile['name'], ".") 1);
    if ($myfile['size'] > $maxSize) {
    $result = 1;
    } else if (!in_array($myfileType, $fileTypes)) {
    $result = 2;
    } elseif (is_uploaded_file($myfile['tmp_name'])) {
    $toFile = $uploadDir . '/' . $myfile['name'];
    if (@move_uploaded_file($myfile['tmp_name'], $toFile)) {
    $result = 0;
    } else {
    $result = -1;
    }
    } else {
    $result = 1;
    }
    }
    ?>
    <script type="text/javascript">
    window.top.window.stopUpload(<?php echo $result; ?>);
    </script>

    本文由68399皇家赌场发布于呼叫中心培训课程,转载请注明出处:PHP无刷新上传文件实现代码,利用iframe实现无刷

    关键词: 68399皇家赌场

    最火资讯