php/apc 监控文件上传进度
原文地址: http://blog.csdn.net/lmss82/archive/2010/05/10/5574772.aspx
这是一个完整可用的代码,部分代码来自于网络。
PHP:
5.26
JS环境:
jquery.js,jquery_form.js
使用步骤:
开启APC.
下载php_apc.dll,修改php.ini文件增加以下内容:
extension=php_apc.dll
apc.rfc1867 = On
代码:
<?php
//<BS>X_REQUESTED_WITH
/* 上传文件 */
if(isset($_FILES['upfile'])){
$uploaddir = $_SERVER['DOCUMENT_ROOT']."/uploadprogress/upfile/";
$uploaddir.= date("YmdHis",time()).'_'.$_FILES['upfile']['name'];
if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $uploaddir))
{
echo "上传成功!";
exit;
}
}
/* 获取上传进度信息 */
if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
if(isset($_GET['APC_UPLOAD_PROGRESS']) && $_GET['do'] == 'retrieving') {
$status = apc_fetch('upload_'.$_GET['APC_UPLOAD_PROGRESS']);
if($status['total']!=0 && !empty($status['total'])) {
$json = array(
'per'=> $status['current']/$status['total']*100,
'total'=> round($status['total']/1024),
'current'=> round($status['current']/1024),
);
echo json_encode($json);
exit;
}
else {
echo (0);
exit;
}
}
}
?>
<mce:script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" mce_src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"><!--
</script >
<script type="text/javascript" src="jquery.form.js" mce_src="jquery.form.js"></script >
<script type="text/javascript">
$(document).ready(function() {
// This is more like it!
$('#upload_form').ajaxForm(function() {
//alert("Thank you for your
相关文档:
根据GyPSii API提供的操作类和方法,发现请求会失败,返回的是一个bed request。原因其实很简单,但一直没有找到,最终原因是对方提供的host是错误的,没天理。
对方提供的host和uri:
host:http://dev3.gypsii.com/gypsii
uri:http://dev3.gypsii.com/gypsii/xmlservice.cgi
这个host就是错的,应该是:dev3.gypsii.co ......
例子. return() 函数的用法
<?php
function square ($num)
{
return $num * $num;
}
echo square (4); // outputs '16'.
?>
函数不能返回多个值,但为了获得简单的结果,可以返回一个列表。
例子. 返回一个数组以得到多个返回值
<?php
function small_numbe ......
转自:http://www.w3school.com.cn/php/func_string_substr.asp
PHP substr() 函数
PHP String 函数
定义和用法
substr() 函数返回字符串的一部分。
语法
substr(string,start,length)
参数描述
string
必需。规定要返回其中一部分的字符串。
start
必需。规定在字符串的何处开始。
正数 - 在字符串的指定位置开 ......
假如一个textarea中有N多行的数据,要将它转为PHP的一维数组,
<form id="textarea_test" action="textarea.php" method="post">
<textarea cols="50" rows="5" name="aa" id="abc" >
<?php
$str = $_POST['aa'];
//var_dump($str);
//$str = "chenjinle le";
$array = explode("\n", trim($ ......