<script language="javascript"> //将上传后的信息返还给父窗口 function chuanzhi(){ parent.document.getElementByIdx_x('filesize').value=document.getElementByIdx_x('size').value; parent.document.getElementByIdx_x('link').value=document.getElementByIdx_x('newsoftdir').value; parent.document.getElementByIdx_x('linkdefult').value=1; } </script> <body> <?php //header('Content-Type:text/html;charset=gb2312'); define('SOFTDIR', "./upload/"); //上传后路径 define('HTTPSOFTDIR', "http://www.mysite.com/"); //服务器的路径 //判断上传软件后缀名是否允许 function isSoftExt($extension) { $ext = array('exe', 'rar', 'zip','gz'); return in_array($extension, $ext) ? true : false; } if($_SERVER['REQUEST_METHOD']=='POST'){ $errors['0'] = true; $errors['1'] = '请选择上传的软件图片'; $errors['2'] = '上传软件图片失败'; $errors['3'] = '上传软件图片失败'; $daytime = date('Y-m-d-h-m-s'); $timename=str_replace("-","",$daytime); //取得当天的日期时间 //检查软件是否是正常上传的 if(!is_uploaded_file($_FILES['Softfile']['tmp_name'])) { echo "<script>alert('非正常上传!');history.back();</script>"; exit; } $extension = pathinfo($_FILES['Softfile']['name'], PATHINFO_EXTENSION); $filename = $timename."_".$_FILES['Softfile']['name']; $tmpsize=$_FILES['Softfile']['size']; $msize=round($tmpsize/1048576 , 2) ."M"; $ksize=round($tmpsize/1024 ,2). "K"; $filesize =$tmpsize>1048576?$msize:$ksize; //检查软件文件格式 if(!isSoftExt($extension)) { echo "<script>alert('上传的软件格式有错误!');history.back();</script>"; exit; } //移动软件 if(!move_uploaded_file($_FILES['Softfile']['tmp_name'], SOFTDIR. $filename)) { echo "<script>alert('移动软件出错!');history.back();</script>"; exit; }else{ echo "<font size=2>上传成功! 文件大小为:<input type=text value='$filesize'></font><br>"; echo "<font size=2>文件下载地址为:</font><input type=text value='".HTTPSOFTDIR.$filename."'>"; } }else echo "请不要直接输入地址!"; ?>
getprogress.php
<?php //上传ajas获取进度页面 session_start(); if(isset($_GET['progress_key'])) { $status = apc_fetch('upload_'.$_GET['progress_key']); echo ($status['current']/$status['total'])*100; } echo 'APC_FILE='.APC_FILE; ?>
本文为大家提供了一个php制作带进度上传文件的思路,可能还有一些欠缺的地方,希望大家进行补充,或者是再结合小编之前整理的文章进行学习,希望对大家的学习有所帮助。
您可能感兴趣的文章: