首页 > 编程技术 > php

php利用flashchart生成柱状图

发布时间:2016-11-25 16:25

php教程利用flashchart生成柱状图

最近项目中需要生成类似excel的柱状图、饼图、趋势图等等。。。

网上google了一番,发现了 Open Flash Chart   地址:  http://teethgrinder.co.uk/open-flash-chart-2/ 。

非常好用的一款开源工具。目前最新版是2.0

——————————————————————————–

http://ofcgwt.googlecode.com/svn/demo/Demo.html 这里有很多示例可供参考。

不过不太推荐使用 googlecode上的这个示例代码,建议采用官方的示例代码和flash chart 。

flash chart的使用很简单。

如下示例:

//url形式
function embSwfWithUrl(dataurl,divcon){
     var params = {
        "wmode": "transparent",
        "menu": "false",
        "scale": "noScale",
        "allowFullscreen": "false",
        "allowScriptAccess": "always",
        "bgcolor": "#c0c0c0"  //背景
    };
    var flashvars = {
        'data-file' : dataurl
    };
    swfobject.embedSWF("/swf/open-flash-chart.swf?timestamp=" + Math.random(),divcon, "450", "300", "10.0.0", "./swf/expressInstall.swf" ,flashvars,params);
}

embSwfWithUrl('http://xxx.com/xxx.html','swfCon');这里的http://xxx.com/xxx.html返回的是相应的json格式的数据。

swfCon是放flash的div容器。

swfobject是开源的js处理flash的类。http://code.google.com/p/swfobject/

——————————————————————————–

注意下,flash chart 获得数据的方式有两种,

一种是   data-file  一种是 get-data

data-file 正是如上示例,值必须是个 url地址,里面返回的是 json数据。

而get-data的值则是一个函数名称。 函数返回 json 数据。

如下示例:

//get-data
function embSwfWithData(divcon,getdataFn){
    var params = {
        "wmode": "transparent",  //窗口模式
        "menu": "false",  //菜单显示
        "scale": "noScale",  //缩放
        "allowFullscreen": "false", //允许全屏
        "allowScriptAccess": "always",  //允许脚本
        "bgcolor": "#c0c0c0"  //背景
    };
var flashVar = {
 "get-data":getdataFn
};
    swfobject.embedSWF("/swf/open-flash-chart.swf?timestamp=" + Math.random(), divcon, "450", "300", "10", "/swf/expressInstall.swf",flashVar  ,params);
}

function getJsonData(){
return 'json data';
}这里 “get-data”:getdataFn

◎Memcached是什么

在阐述这个问题之前,我们首先要清楚它“不是什么”。很多人把它当作和SharedMemory那种形式的存储载体来使用,虽然memcached 使用了同样的“Key=>Value”方式组织数据,但是它和共享内存、APC等本地缓存有非常大的区别。Memcached是分布式的,也就是说它不是本地的。它基于网络连接(当然它也可以使用localhost)方式完成服务,本身它是一个独立于应用的程序或守护进程(Daemon方式)。

Memcached使用libevent库实现网络连接服务,理论上可以处理无限多的连接,但是它和Apache不同,它更多的时候是面向稳定的持续连接的,所以它实际的并发能力是有限制的。在保守情况下memcached的最大同时连接数为200,这和Linux线程能力有关系,这个数值是可以调整的。关于libevent可以参考相关文档。 Memcached内存使用方式也和APC不同。APC是基于共享内存和MMAP的,memcachd有自己的内存分配算法和管理方式,它和共享内存没有关系,也没有共享内存的限制,通常情况下,每个memcached进程可以管理2GB的内存空间,如果需要更多的空间,可以增加进程数。

◎Memcached适合什么场合

在很多时候,memcached都被滥用了,这当然少不了对它的抱怨。我经常在论坛上看见有人发贴,类似于“如何提高效率”,回复是“用memcached”,至于怎么用,用在哪里,用来干什么一句没有。memcached不是万能的,它也不是适用在所有场合。

Memcached是“分布式”的内存对象缓存系统,那么就是说,那些不需要“分布”的,不需要共享的,或者干脆规模小到只有一台服务器的应用,memcached不会带来任何好处,相反还会拖慢系统效率,因为网络连接同样需要资源,即使是UNIX本地连接也一样。 在我之前的测试数据中显示,memcached本地读写速度要比直接PHP内存数组慢几十倍,而APC、共享内存方式都和直接数组差不多。可见,如果只是本地级缓存,使用memcached是非常不划算的。

Memcached在很多时候都是作为数据库教程前端cache使用的。因为它比数据库少了很多SQL解析、磁盘操作等开销,而且它是使用内存来管理数据的,所以它可以提供比直接读取数据库更好的性能,在大型系统中,访问同样的数据是很频繁的,memcached可以大大降低数据库压力,使系统执行效率提升。另外,memcached也经常作为服务器之间数据共享的存储媒介,例如在SSO系统中保存系统单点登陆状态的数据就可以保存在memcached 中,被多个应用共享。

需要注意的是,memcached使用内存管理数据,所以它是易失的,当服务器重启,或者memcached进程中止,数据便会丢失,所以 memcached不能用来持久保存数据。很多人的错误理解,memcached的性能非常好,好到了内存和硬盘的对比程度,其实memcached使用内存并不会得到成百上千的读写速度提高,它的实际瓶颈在于网络连接,它和使用磁盘的数据库系统相比,好处在于它本身非常“轻”,因为没有过多的开销和直接的读写方式,它可以轻松应付非常大的数据交换量,所以经常会出现两条千兆网络带宽都满负荷了,memcached进程本身并不占用多少CPU资源的情况。

php教程图片上传,可实现预览

<?php
header("content-Type: text/html; charset=gb2312");
$uptypes=array('image/jpg',  //上传文件类型列表
 'image/jpeg',
 'image/png',
 'image/pjpeg',
 'image/gif',
 'image/bmp',
 'application/x-shockwave-flash',
 'image/x-png',
 'application/msword',
 'audio/x-ms-wma',
 'audio/mp3',
 'application/vnd.rn-realmedia',
 'application/x-zip-compressed',
 'application/octet-stream');

$max_file_size=10000000;   //上传文件大小限制, 单位BYTE
$path_parts=pathinfo($_SERVER['PHP_SELF']); //取得当前路径
$destination_folder="up/"; //上传文件路径
$watermark=0;   //是否附加水印(1为加水印,0为不加水印);
$watertype=1;   //水印类型(1为文字,2为图片)
$waterposition=2;   //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);
$waterstring="www.yinao.tk"; //水印字符串
$waterimg="xplore.gif";  //水印图片
$imgpreview=1;   //是否生成预览图(1为生成,0为不生成);
$imgpreviewsize=1/1;  //缩略图比例
?>
<html xmlns="undefined">
<head>
<title>图片上传储存</title>
<style type="text/css教程">
body,td{font-family:tahoma,verdana,arial;font-size:11px;line-height:15px;background-color:white;color:#666666;
strong{font-size:12px;}
a:link{color:#0066CC;}
a:hover{color:#FF6600;}
a:visited{color:#003366;}
a:active{color:#9DCC00;}
a{TEXT-DECORATION:none}
td.irows{height:20px;background:url("index.php?i=dots") repeat-x bottom}
</style>
</head>
<script type="text/网页特效">function oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy");};function sendtof(url){window.clipboardData.setData('Text',url);alert('复制地址成功,粘贴给你好友一起分享。');};function select_format(){var on=document.getElementById('fmt').checked;document.getElementById('site').style.display=on?'none':'';document.getElementById('sited').style.display=!on?'none':'';};var flag=false;function DrawImage(ImgD){var image=new Image();image.src=ImgD.src;if(image.width>0&&image.height>0){flag=true;if(image.width/image.height>=120/80){if(image.width>120){ImgD.width=120;ImgD.height=(image.height*120)/image.width;}else {ImgD.width=image.width;ImgD.height=image.height;};ImgD.alt=image.width+"×"+image.height;}else {if(image.height>80){ImgD.height=80;ImgD.width=(image.width*80)/image.height;}else {ImgD.width=image.width;ImgD.height=image.height;};ImgD.alt=image.width+"×"+image.height;}};};function FileChange(Value){flag=false;document.all.uploadimage.width=10;document.all.uploadimage.height=10;document.all.uploadimage.alt="";document.all.uploadimage.src=Value;};</script>
<body bgcolor="#FFFFFF">
<center>
  <form enctype="multipart/form-data" method="post" name="upform">
    <table border="1" width="55%" id="table1" cellspacing=0>
      <tr>
        <td colspan="2"><p align="center">最大文件限制1M </td>
      </tr>
      <tr>
        <td width="10%"><div style="width:120px; height:80px;overflow:hidden;text-align: center;" ><IMG id=uploadimage height=0 width=0" width=100% src=""  onload="javascript:DrawImage(this);" ></div></td>
        <td width="71%"><div style="width:361px; height:80px;overflow:hidden;text-align: center;padding:30px; " >
          <input style="width:208;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff; height:18" size="17" name=upfile type=file
onchange="javascript:FileChange(this.value);">
          <input type="submit" value="上传" style="width:60;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff; height:18" size="17"></td>
      </tr>
    </table>
    允许上传的文件类型为:jpg|jpeg|gif|bmp|png|swf|mp3|wma|zip|rar|doc</form>
  <?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!is_uploaded_file($_FILES["upfile"][tmp_name]))
//是否存在文件
{
echo "<font color='red'>文件不存在!</font>";
exit;
}

 $file = $_FILES["upfile"];
 if($max_file_size < $file["size"])
 //检查文件大小
 {
 echo "<font color='red'>文件太大!</font>";
 exit;
  }

if(!in_array($file["type"], $uptypes))
//检查文件类型
{
 echo "<font color='red'>不能上传此类型文件!</font>";
 exit;
}

if(!file_exists($destination_folder))
mkdir($destination_folder);

$filename=$file["tmp_name"];
$image_size = getimagesize($filename);
$pinfo=pathinfo($file["name"]);
$ftype=$pinfo[extension];
$destination = $destination_folder.time().".".$ftype;
if (file_exists($destination) && $overwrite != true)
{
     echo "<font color='red'>同名文件已经存在了!</a>";
     exit;
  }

 if(!move_uploaded_file ($filename, $destination))
 {
   echo "<font color='red'>移动文件出错!</a>";
     exit;
  }

$pinfo=pathinfo($destination);
$fname=$pinfo[basename];
echo " <font color=red>成功上传,鼠标移动到地址栏自动复制</font><br><table width="348" cellspacing="0" cellpadding="5" border="0" class="table_decoration" align="center"><tr><td><input type="checkbox" id="fmt" onclick="select_format()"/>图片UBB代码<br/><div id="site"><table border="0"><tr><td valign="top">文件地址:</td><td><input type="text" onclick="sendtof(this.value)" onmouseo教程ver="oCopy(this)" style=font-size=9pt;color:blue size="44" value="http://".$_SERVER['SERVER_NAME'].$path_parts["dirname"]."/".$destination_folder.$fname.""/>
</td></tr></table></div><div id="sited" style="display:none"><table border="0"><tr><td valign="top">文件地址:</td><td><input type="text" onclick="sendtof(this.value)" onmouseover="oCopy(this)" style=font-size=9pt;color:blue size="44" value="[img]http://".$_SERVER['SERVER_NAME'].$path_parts["dirname"]."/".$destination_folder.$fname."[/img]"/></td></tr></table></div></td></tr></table>";
echo " 宽度:".$image_size[0];
echo " 长度:".$image_size[1];
if($watermark==1)
{
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);
$white=imagecolorallocate($nimage,255,255,255);
$black=imagecolorallocate($nimage,0,0,0);
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white);
switch ($iinfo[2])
{
 case 1:
 $simage =imagecreatefromgif($destination);
 break;
 case 2:
 $simage =imagecreatefromjpeg($destination);
 break;
 case 3:
 $simage =imagecreatefrompng($destination);
 break;
 case 6:
 $simage =imagecreatefromwbmp($destination);
 break;
 default:
 die("<font color='red'>不能上传此类型文件!</a>");
 exit;
}

imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);
imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);

switch($watertype)
{
 case 1:  //加水印字符串
 imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
 break;
 case 2:  //加水印图片
 $simage1 =imagecreatefromgif("xplore.gif");
 imagecopy($nimage,$simage1,0,0,0,0,85,15);
 imagedestroy($simage1);
 break;
}

switch ($iinfo[2])
{
 case 1:
 //imagegif($nimage, $destination);
 imagejpeg($nimage, $destination);
 break;
 case 2:
 imagejpeg($nimage, $destination);
 break;
 case 3:
 imagepng($nimage, $destination);
 break;
 case 6:
 imagewbmp($nimage, $destination);
 //imagejpeg($nimage, $destination);
 break;
}

//覆盖原上传文件
imagedestroy($nimage);
imagedestroy($simage);
}

if($imgpreview==1)
{
echo "<br>图片预览:<br>";
echo "<a href="".$destination."" target='_blank'><img" width=100% src="".$destination."" width=".($image_size[0]*$imgpreviewsize)." height=".($image_size[1]*$imgpreviewsize);
echo " alt="图片预览:r文件名:".$fname."r上传时间:".date('m/d/Y h:i')."" border='0'></a>";
}
}
?>
</center>
</body>
</html>

实用的php教程购物车程序
以前有用过一个感觉不错,不过看了这个感觉也很好,所以介绍给需要的朋友参考一下。

<?php
//调用实例
require_once 'cart.class.php';
session_start();
if(!isset($_SESSION['cart'])) {
 $_SESSION['cart'] = new Cart;
}
$cart =& $_SESSION['cart'];

if( ($_SERVER['REQUEST_METHOD']=="POST")&&($_POST['action']=='add') ){
 $p = $_POST['p'];
 $items = $cart->add($p);
}
if( ($_GET['action']=='remove')&&($_GET['key']!="") ) {
 $items = $cart->remove($_GET['key']);
}

if( ($_SERVER['REQUEST_METHOD']=="POST")&&($_POST['action']=='modi') ){
 $key = $_POST['key'];
 $value = $_POST['value'];
 for($i=0;$i<count($key);$i  ){
  $items = $cart->modi($key[$i],$value[$i]);
 }
}

$items = $cart->getCart();
//打印
echo "<table border=1>";
setlocale(LC_MONETARY, 'it_IT');
foreach($items as $item){
 echo "<tr><form method="post" action="tmp.php">";
 echo "<td>ID:".$item['ID']."<input type=hidden name=key[] value=".$item['ID'].">";
 echo "<td>产品:".$item['name'];
 echo "<td>单价:".$item['price'];
 echo "<td><input type=text name=value[] value=".$item['count'].">";
  $sum = $item['count']*$item['price'];
 echo "<td>合计:".round($sum,2);
 echo "<td><input type=button value='删除' onclick="location='?action=remove&key=".$item['ID']."'">";
}
echo "<input type=hidden name=action value=modi>";
echo "<tr><td colspan=7><input type=submit />";
echo "</td></form></tr></table>";


?>
<hr>
<form method="post" action="tmp.php">
ID:<input type="text" name="p[]" />
品名:<input type="text" name="p[]" />
单价:<input type="text" name="p[]" />
数量:<input type="text" name="p[]" />
<input type=hidden name=action value=add>
<input type="submit" />
</form>

 

<?
/**
 * Cart
 *
 * 购物车类
 *
 * @author  doodoo<pWtitle@yahoo.com.cn>
 * @package     Cart
 * @category    Cart
 * @license     PHP License
 * @access      public
 * @version     $Revision: 1.10 $
 */
Class Cart{

 var $cart;
 var $totalCount; //商品总数量
 var $totalPrices; //商品总金额

  /**
     * Cart Constructor
     *
     * 类的构造函数,使购物车保持稳定的初始化状态
     *
     * @static
     * @access  public
     * @return  void   无返回值
     * @param   void   无参数
     */
  function Cart(){
  $this->totalCount = 0;
  $this->totalPrice = 0;
  $this->cart = array();
 }
 
 // }}}
    // {{{ add($item)

    /**
 * 增加商品到当前购物车
 *
    * @access public
    * @param  array $item 商品信息(一维数组:array(商品ID,商品名称,商品单价,商品数量))
    * @return array   返回当前购物车内商品的数组
    */
 function add($item){
  if(!is_array($item)||is_null($item)) return $this->cart;
  if(!is_numeric(end($item))||(!is_numeric(prev($item)))) {
   echo "价格和数量必须是数字";
   return $this->cart;
  }
  reset($item); //这一句是必须的,因为上面的判断已经移动了数组的指标
  $key = current($item);
  if($key=="") return $this->cart;
  if($this->_isExists($key)){  //商品是否已经存在?
    $this->cart[$key]['count']  = end($item);
  return $this->cart;
  }

  $this->cart[$key]['ID']  = $key;
  $this->cart[$key]['name'] = next($item);
  $this->cart[$key]['price'] = next($item);
  $this->cart[$key]['count'] = next($item);

 return $this->cart;
 }

 // }}}
    // {{{ add($item)

    /**
 * 从当前购物车中取出部分或全部商品
 * 当 $key=="" 的时候,清空当前购物车
 * 当 $key!=""&&$count=="" 的时候,从当前购物车中拣出商品ID号为 $key 的全部商品
 * 当 $key!=""&&$count!="" 的时候,从当前购物车中拣出 $count个 商品ID号为 $key 的商品
 *
    * @access public
    * @param  string $key 商品ID
    * @return mixed   返回真假或当前购物车内商品的数组
    */
 function remove($key="",$count=""){
  if($key=="") {
   $this->cart = array();
   return true;
  }
  if(!array_key_exists($key,$this->cart)) return false;
  if($count==""){ //移去这一类商品
   unset($this->cart[$key]);
  }else{ //移去$count个商品
   $this->cart[$key]['count'] -= $count;
   if($this->cart[$key]['count']<=0) unset($this->cart[$key]);
  }
  return $this->cart;
 }

 // }}}
    // {{{ modi($key,$value)

    /**
 * 修改购物车内商品ID为 $key 的商品的数量为 $value
 *
    * @access public
    * @param  string $key 商品ID
    * @param  int $value 商品数量
    * @return array  返回当前购物车内商品的数组;
    */
 function modi($key,$value){
  if(!$this->_isExists($key)) return $this->cart();  //不存在此商品,直接返回
  if($value<=0){     // value 太小,全部删除
   unset($this->cart[$key]);
   return $this->cart;
  }
  $this->cart[$key]['count'] = $value;
  return $this->cart;
 }


    /**
 * 返回当前购物车内商品的数组
 *
    * @access public
    * @return array  返回当前购物车内商品的数组;
    */
 function getCart(){
  return $this->cart;
 }

 // }}}
    // {{{ _isExists($key)

    /**
 * 判断当前购物车中是否存在商品ID号为$key的商品
 *
    * @access private
    * @param  string $key 商品ID
    * @return bool   true or false;
    */
    function _isExists($key)
    {
  if(isset($this->cart[$key])&&!empty($this->cart[$key])&&array_key_exists($key,$this->cart))
   return true;
    return false;
    }

 // }}}
    // {{{ isEmpty()

    /**
 * 判断当前购物车是否为空,即没有任何商品
 *
    * @access public
    * @return bool   true or false;
    */
 function isEmpty(){
  return !count($this->cart);
 }

 // }}}
    // {{{ _stat()

    /**
 * 取得部分统计信息
 *
    * @access private
    * @return bool  true or false;
    */
 function _stat(){
  if($this->isEmpty()) return false;
  foreach($this->cart as $item){
   $this->totalCount   = @end($item);
   $this->totalPrices  = @prev($item);
  }
  return true;
 }

 // }}}
    // {{{ totalPrices()

    /**
 * 取得当前购物车所有商品的总金额
 *
    * @access public
    * @return float  返回金额;
    */
 function totalPrices(){
  if($this->_stat())
   return $this->totalPrices;
 return 0;
 }

 // }}}
    // {{{ isEmpty()

    /**
 * 取得当前购物车所有商品的总数量和
 *
    * @access public
    * @return int ;
    */
 function totalCount(){
  if($this->_stat())
   return $this->totalCount; 
 return 0;
 }


}//End Class Cart
?>

主要目的就是测试我的php.ini没有设置upload_dir_tmp的值的时候,上传的文件临时保存在哪里的,经过这个测试发现原来在不配置php.ini的upload_dir_tmp的值的时候,默认的存储位置是在 C:\windows\temp目录,并且临时文件是以.tmp为后缀存储的,该文件马上就会被删除,所以你想通过操作系统的文件修改搜索功能是无法找到的,也就无法找到upload_dir_tmp的默认路径是哪里。

IIS+php教程服务器无法上传图片解决办法

服务器上使用Apache2+PHP正常运行,换成IIS+PHP,先后出现了php.ini的环境变量无法读取,php中验证码无法显示的问题,如今又有人反应无法上传图片的问题。

   从IIS替换Apache2的过程仅仅是开启IIS,关闭Apache2,其它的没什么变化,但是却发生了如此多的差异,看样子IIS支持PHP还是有很多要进行修改的。

分析:

   根据上面的描述,我怀疑问题出在IIS的权限配置上,IUSR_MACHINE的帐户对upload没有写入的权限,于是进行权限修改,IIS下的权限,NTFS下的权限都进行修改,但是终究都没用,查找网络上的资料也没有相应的,对上传页面进行测试,流程为:

   swf文件调用save.php上传文件---->swf文件对上传的文件进行重命名--->名字返回给save.php--->显示出最后的名字。

   现在的问题一直停留在swf对文件重命名的这里,一直没有到显示出最后的名字,并且swf文件不参与上传过程,那就只能在save.php文件中进行问题查找了,在该文件中进行测试,最后显示的名字所使用的变量为fileName,于是插入下面的语句进行测试:

   echo "fileName=2008*****.gif";

   这句话的作用就是使得fileName有值,save.php能正常显示,先把原来的语句一句一句的进行屏蔽测试,都正常的返回了,但是当测试到:
    if (!@move_uploaded_file($f["tmp_name"], $dest_dir.'/'.$fileName)) header("HTTP/1.0 404 Not Found");
   这句话的时候问题出现了,不能上传,查找上下文,一直没发现tmp_name的变量,不过看意思是先把文件上传到一个临时文件,再挪动到目的位置,那这个tmp位置在哪里呢?是不是这个位置不可写,才导致了无法上传文件?

   查找网上资料,发现php.ini下面有2个地方关于上传的配置:
file_uploads = On                          这里设置是否允许HTTP上传,默认应该为ON的
   ;upload_tmp_dir=                          这里设置上传文件存放的临时位置

网上对于这2个地方的相关资料有:
I try to set up file uploading under IIS 7 and PHP 5.

First problem was to set 2 variables in php.ini

file_uploads = On           //这里是说php.ini文件这个地方设置成On

upload_tmp_dir = "C:Inetpubwwwrootuploads"    //这个路径就是自己设置的上传文件临时存储路径

For some reasons such directory name works,
but "upload_tmp" won't work.

The second problem was to set correct user rigths for upload folders where you try to save your file. I set my upload folder rights for the "WORKGROUP/users" for the full access. You may experiment by yourselves if you not need execute access, for example.

    我的php.ini中upload_tmp_dir是被注释的,没有启用,更没有设置,可是为什么Apache2却可以正常上传呢?难道问题真的出在这里?

解决:

   新建一个文件夹做临时上传目录,按照上面的英文说明修改php.ini中相应的那2项,把临时上传目录upload_tmp_dir设置成刚才建立的文件夹,把该文件夹的权限赋予“IUSR_计算机名”用户可写,重新启动IIS,上传试试,问题真的就这样解决了。


最终的分析答案:

   上面的内容写于09年,但是现在2010年7月我新增一台服务器,又出现了这个问题,同时再次按照上面的解决方法实施,在操作的过程中大概是由于哪里出了错,竟然没有成功,不得不抽出点时间来研究具体原因,找到了最终产生这个问题的原因如下。
    无法上传文件,不代表所有文件都无法上传,因为我的一个网站,flash调用fwrite()传头像之类的成功了,但是调用@move_uploaded_file($f["tmp_name"], $dest_dir.'/'.$fileName)这样的函数传照片的时候仍旧无法上传。
   经过我的分析,原因是由于fwrite()是传的二进制文件,而move_uploaded_file()传的是文本文件,而windows操作系统是区分这2种文件的 [参考php手册fwrite()函数的说明],这也就是说这2种不同的文件在php环境下上传时所存储的临时上传目录是不同的,由于在配置IIS环境下的PHP的时候,设置的临时目录为E:tmp,设置该目录的iusr用户可写,二进制文件即可上传,所以我怀疑该目录就是二进制文件上传临时文件的存储位置,那么move_uploaded_file()传的文本文件的临时文件存储位置在哪里呢?其实就是在上面的那段英文里面,upload_tmp_dir设置的路径就是了,但是我的几台服务器中,每台服务器的这个设置的值都是被注释掉的“no value”,为什么有的服务器可以上传,而有的服务器不可以上传呢?这也就回到了以前我提出的问题,为什么Apache2可以上传而iis不可以上传呢?
    这次我再次分析upload.php文件,分析其中造成该故障的代码具体内容如下:

// 检查是否有文件上传
    if (! $_FILES['upload'.$num]['name'] == ""){
      if ($_FILES['upload'.$num]['size'] < $max_size) { 
   1、 echo "文件上传路径:".$location.$_FILES['upload'.$num]['name'];
    2、echo "文件临时文件名:".$_FILES['upload'.$num]['tmp_name'];
    3、    move_uploaded_file($_FILES['upload'.$num]['tmp_name'],$location.$_FILES['upload'.$num]['name']) or $event = "Failure";
    } else {
     $event = "File too large!";
    }

   其中正常代码中第2句是不存在的,为了测试方便我加上来的,它的主要目的就是测试我的php.ini没有设置upload_dir_tmp的值的时候,上传的文件临时保存在哪里的,经过这个测试发现原来在不配置php.ini的upload_dir_tmp的值的时候,默认的存储位置是在 C:windowstemp目录,并且临时文件是以.tmp为后缀存储的,该文件马上就会被删除,所以你想通过操作系统的文件修改搜索功能是无法找到的,也就无法找到upload_dir_tmp的默认路径是哪里。

   既然找到了upload_dir_tmp的默认路径了,那么修改c:windowstemp的访问权限,赋予IUSR_用户可写,重启动IIS Admin服务,上传文件,终于成功了。这就是为什么我的多台服务器upload_dir_tmp的值都为空的时候有的可传,有的不可传的原因。

标签:[!--infotagslink--]

您可能感兴趣的文章: