php 实现多文件上传程序代码

 更新时间:2016年11月25日 16:21  点击:1708
php文件上传与多文件上传其它没有多大的区别,多文件上传只是我们把表单名改成数组形式,而获取利用foreach遍历就可以实现多文件上传了,动态多文件上传只要在js加一个动态增加多文件上传框,同样在php处理时就遍历一下数组就成了。

最简单的实例如下

 代码如下 复制代码

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>

       <?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
            $name = $_FILES["pictures"]["name"][$key];
            move_uploaded_file($tmp_name, "data/$name");
        }
}
?>

 

下面分享其它朋友的例子
例1

 代码如下 复制代码

<?
//filename:multi_upload.php
if($ifupload)
{
$path=AddSlashes(dirname($PATH_TRANSLATED))."\upload\";
for($i=1;$i<=8;$i++)
{
$files="afile".$i;
if(${$files}!="none")
{
if(copy(${$files},$path.${$files."_name"}))
{
}
}
}
print "<b>You have uploaded files successfully</b><br>";
print "<a href="multi_upload.php">Return</a>";
exit;
}
?>
<html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>多个文件上传</title>
<style type="text/css">
<!--
BODY
{
PADDING-RIGHT: 0px;
MARGIN-TOP: 0px;
PADDING-LEFT: 0px;
FONT-SIZE: 8px;
MARGIN-LEFT: 0px;
CURSOR: default;
COLOR: black;
MARGIN-RIGHT: 0px;
PADDING-TOP: 0px;
FONT-FAMILY: Arial;
BACKGROUND-COLOR: transparent;
TEXT-ALIGN: center
}
.TxtInput
{
FONT-SIZE: 8pt;
WIDTH: 100%;
CURSOR: default;
COLOR: black;
FONT-FAMILY: Arial;
HEIGHT: 21px;
BACKGROUND-COLOR: white;
TEXT-ALIGN: left
}
.FieldLabel
{
FONT-WEIGHT: normal;
FONT-SIZE: 9pt;
WIDTH: 100%;
COLOR: black;
FONT-FAMILY: Arial;
BACKGROUND-COLOR: transparent;
TEXT-ALIGN: left
}
.HeadBtn
{
BORDER-RIGHT: black 1px solid;
BORDER-TOP: white 1px solid;
FONT-SIZE: 8pt;
OVERFLOW: hidden;
BORDER-LEFT: white 1px solid;
WIDTH: 70px;
COLOR: black;
BORDER-BOTTOM: black 1px solid;
FONT-FAMILY: Arial;
HEIGHT: 21px;
BACKGROUND-COLOR: #8e8dcd;
TEXT-ALIGN: center
}
.TransEx
{
BORDER-RIGHT: black 1px solid;
PADDING-RIGHT: 8px;
BORDER-TOP: white 1px solid;
PADDING-LEFT: 8px;
FONT-SIZE: 8pt;
PADDING-BOTTOM: 3px;
BORDER-LEFT: white 1px solid;
WIDTH: 720px;
PADDING-TOP: 3px;
BORDER-BOTTOM: black 1px solid;
FONT-FAMILY: Arial;
BACKGROUND-COLOR: #c0c0c0;
TEXT-ALIGN: center
}
-->
</style>
<script language="javascript">
function window.onload()
{
document.forms[0].btnOk.onclick=btn_ok;
}
function btn_ok()
{
for(var i=1;i<=8;i++)
{
if(eval("document.forms[0].afile"+i+".value!=''"))
document.forms[0].submit();
return true;
}
alert("None of file have been selected");
return false;
}
</script>
</head>
<body>
<form method="post" action="multi_upload.php" name="frmUpload" enctype="multipart/form-data" >
<table id="divContainer" style="HEIGHT: 100%; WIDTH: 380" border="0">
<tr height="35"><td align="right" valign="bottom">多文件上传 </td></tr>
<tr><td align="center" valign="top">
<table class="Transex" border="0" cellspacing="0" cellpadding="0" style="WIDTH: 360px">
<tr style="HEIGHT: 10px" >
<td style="WIDTH: 5px"></td>
<td colspan="2"></td>
<td style="WIDTH: 5px"></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件1</label></td>
<td><input type="file" class="TxtInput" tabindex="1" name="afile1" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件2</label></td>
<td><input type="file" class="TxtInput" tabindex="2" name="afile2" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件3</label></td>
<td><input type="file" class="TxtInput" tabindex="3" name="afile3" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件4</label></td>
<td><input type="file" class="TxtInput" tabindex="4" name="afile4" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件5</label></td>
<td><input type="file" class="TxtInput" tabindex="5" name="afile5" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件6</label></td>
<td><input type="file" class="TxtInput" tabindex="6" name="afile6" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件7</label></td>
<td><input type="file" class="TxtInput" tabindex="7" name="afile7" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr>
<td></td>
<td nowrap><label class="FieldLabel"> 文件8</label></td>
<td><input type="file" class="TxtInput" tabindex="8" name="afile8" style="WIDTH: 282px"></td>
<td></td>
</tr>
<tr style="HEIGHT: 5px">
<td style="WIDTH: 5px">
<td style="WIDTH: 350px" colspan="2"><hr width="100%"></td>
<td style="WIDTH: 5px"></td>
</tr>
<tr>
<td></td>
<td colspan="2" align="left">
<button tabindex="5" class="headbtn" align="center" name="btnOk" id="btnOk" accesskey="O">确定(<ins>O</ins>)</button>
<input type="hidden" name="ifupload" value=1>
<button tabindex="5" class="headbtn" align="center" name="btnCancel" id="btnCancel" accesskey="C" onclick="window.close();">取消(<ins>C</ins>)</button></td>
<td></td>
</tr>
<tr style="HEIGHT: 5px">
<td style="WIDTH: 5px">
<td style="WIDTH: 350px" colspan="2"></td>
<td style="WIDTH: 5px"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>


如果我们要动态不确定性的多文件上传怎么实现下面也有实例

文件上传代码

 代码如下 复制代码
view plaincopy to clipboardprint?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文档上传</title>
</head>
<body>
<script language="javascript"><!--
动态添加文件选择控件-->
function AddRow()
{
var eNewRow = tblData.insertRow();
for (var i=0;i<1;i++)
{
var eNewCell = eNewRow.insertCell();
eNewCell.innerHTML = "<tr><td><input type='file' name='filelist[]' size='50'/></td></tr>";
}
}
// --></script>
<form name="myform" method="post" action="uploadfile.php" enctype="multipart/form-data" >
<table id="tblData" width="400" border="0">
<!-- 将上传文件必须用post的方法和enctype="multipart/form-data" -->
<!-- 将本页的网址传给uploadfile.php-->
<input name="postadd" type="hidden" value="<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER["PHP_SELF"]; ?>" />
<tr><td>文件上传列表
<input type="button" name="addfile" onclick="AddRow()" value="添加列表" /></td></tr>
<!-- filelist[]必须是一个数组-->
<tr><td><input type="file" name="filelist[]" size="50" /></td></tr>
</table>
<input type="submit" name="submitfile" value="提交文件" />
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文档上传</title>
</head>
<body>
<script language="javascript"><!--
动态添加文件选择控件-->
function AddRow()
{
var eNewRow = tblData.insertRow();
for (var i=0;i<1;i++)
{
var eNewCell = eNewRow.insertCell();
eNewCell.innerHTML = "<tr><td><input type='file' name='filelist[]' size='50'/></td></tr>";
}
}
// --></script>
<form name="myform" method="post" action="uploadfile.php" enctype="multipart/form-data" >
<table id="tblData" width="400" border="0">
<!-- 将上传文件必须用post的方法和enctype="multipart/form-data" -->
<!-- 将本页的网址传给uploadfile.php-->
<input name="postadd" type="hidden" value="<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER["PHP_SELF"]; ?>" />
<tr><td>文件上传列表
<input type="button" name="addfile" onclick="AddRow()" value="添加列表" /></td></tr>
<!-- filelist[]必须是一个数组-->
<tr><td><input type="file" name="filelist[]" size="50" /></td></tr>
</table>
<input type="submit" name="submitfile" value="提交文件" />
</form>
</body>
</html>
提交文件代码
view plaincopy to clipboardprint?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文件上传结果</title>
</head>
<body>
<?php
if ($_POST["submitfile"]!="")
{
$Path="./".date('Ym')."/";
if (!is_dir($Path))//创建路径
{ mkdir($Path); }
echo "<div>";
for ($i=0;$i<count($filelist);$i++)
{ //$_FILES["filelist"]["size"][$i]的排列顺序不可以变,因为fileist是一个二维数组
if ($_FILES["filelist"]["size"][$i]!=0)
{
$File=$Path.date('Ymdhm')."_".$_FILES["filelist"]["name"][$i];
if (move_uploaded_file($_FILES["filelist"]["tmp_name"][$i],$File))
{ echo "文件上传成功 文件类型:".$_FILES["filelist"]["type"][$i]." "."文件名:"
.$_FILES["filelist"]["name"][$i]."<br>"; }
else
{ echo "文件名:".$_FILES["filelist"]["name"][$i]."上传失败</br>"; }
}
}
echo "</div><br><a href="$postadd" href="$postadd">返回</a></div>";
}
?>
</body>
</html>

另:错误信息说明
从 PHP 4.2.0 开始,PHP 将随文件信息数组一起返回一个对应的错误代码。该代码可以在文件上传时生成的文件数组中的 error 字段中被找到,也就是 $_FILES['userfile']['error']。
UPLOAD_ERR_OK
其值为 0,没有错误发生,文件上传成功。
UPLOAD_ERR_INI_SIZE
其值为 1,上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。
UPLOAD_ERR_FORM_SIZE
其值为 2,上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。 UPLOAD_ERR_PARTIAL
其值为 3,文件只有部分被上传。
UPLOAD_ERR_NO_FILE
其值为 4,没有文件被上传。
UPLOAD_ERR_NO_TMP_DIR
其值为 6,找不到临时文件夹。PHP 4.3.10 和 PHP 5.0.3 引进。
UPLOAD_ERR_CANT_WRITE
其值为 7,文件写入失败。PHP 5.1.0 引进。
注意: 以上值在 PHP 4.3.0 之后变成了 PHP 常量。

本文章给大家来总结几种实现下载短点续传程序功能,这些函数中主要是用到了php的header函数,有需要了解的朋友可进入参考。

例如:下载时输出  下载文件大小,文件名等等
前提是.htaccess文件的配置需要添加一句
SetEnv no-gzip dont-vary
就是针对文件不进行压缩处理

例1

 代码如下 复制代码

<?php
function download($file_dir,$file_name)
//参数说明:
//file_dir:文件所在目录
//file_name:文件名
{
$file_dir = chop($file_dir);//去掉路径中多余的空格
//得出要下载的文件的路径
if($file_dir != '')
{
$file_path = $file_dir;
if(substr($file_dir,strlen($file_dir)-1,strlen($file_dir)) != '/')
$file_path .= '/';
$file_path .= $file_name;
} else {
$file_path = $file_name;
}
//判断要下载的文件是否存在
if(!file_exists($file_path))
{
echo '对不起,你要下载的文件不存在。';
return false;
}
$file_size = filesize($file_path);
@header("Cache-control: public");
@header("Pragma: public");
//header("Content-Encoding: gzip");
@header("Content-Type: application/octetstream");
header("Content-Length: $file_size");
Header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=".$file_name);
$fp = fopen($file_path,"r");
fpassthru($fp);
return true;
}
download('路径参数','文件名');
?>

例2

 代码如下 复制代码
$fname = './MMLDZG.mp3'; 
$fp = fopen($fname,'rb'); 
$fsize = filesize($fname); 
if (isset($_SERVER['HTTP_RANGE']) && ($_SERVER['HTTP_RANGE'] != "") && preg_match("/^bytes=([0-9]+)-$/i", $_SERVER['HTTP_RANGE'], $match) && ($match[1] < $fsize)) {
    $start = $match[1];
} else {
    $start = 0;
}
@header("Cache-control: public"); @header("Pragma: public");
if ($star--> 0) { 
    fseek($fp, $start); 
    Header("HTTP/1.1 206 Partial Content"); 
    Header("Content-Length: " . ($fsize - $start)); 
    Header("Content-Ranges: bytes" . $start . "-" . ($fsize - 1) . "/" . $fsize); 
} else { 
    header("Content-Length: $fsize"); 
    Header("Accept-Ranges: bytes"); 

@header("Content-Type: application/octet-stream"); 
@header("Content-Disposition: attachment;filename=mmdld.mp3"); 
fpassthru($fp); 
 


fpassthru() 函数输出文件指针处的所有剩余数据。

该函数将给定的文件指针从当前的位置读取到 EOF,并把结果写到输出缓冲区

上面两个实例对中文支持不好,下面这个函数很好的解决了这个问题

 代码如下 复制代码

 <?php

  /**

  * PHP-HTTP断点续传实现

  * @param string $path: 文件所在路径

  * @param string $file: 文件名

  * @return void

  */

  function download($path,$file) {

  $real = $path.'/'.$file;

  if(!file_exists($real)) {

  return false;

  }

  $size = filesize($real);

  $size2 = $size-1;

  $range = 0;

  if(isset($_SERVER['HTTP_RANGE'])) {

  header('HTTP /1.1 206 Partial Content');

  $range = str_replace('=','-',$_SERVER['HTTP_RANGE']);

  $range = explode('-',$range);

  $range = trim($range[1]);

  header('Content-Length:'.$size);

  header('Content-Range: bytes '.$range.'-'.$size2.'/'.$size);

  } else {

  header('Content-Length:'.$size);

  header('Content-Range: bytes 0-'.$size2.'/'.$size);

  }

  header('Accenpt-Ranges: bytes');

  header('application/octet-stream');

  header("Cache-control: public");

  header("Pragma: public");

  //解决在IE中下载时中文乱码问题

  $ua = $_SERVER['HTTP_USER_AGENT'];

  if(preg_match('/MSIE/',$ua)) {

  $ie_filename = str_replace('+','%20',urlencode($file));

  header('Content-Dispositon:attachment; filename='.$ie_filename);

  } else {

  header('Content-Dispositon:attachment; filename='.$file);

  }

  $fp = fopen($real,'rb+');

  fseek($fp,$range);

  while(!feof($fp)) {

  set_time_limit(0);

  print(fread($fp,1024));

  flush();

  ob_flush();

  }

  fclose($fp);

  }

  /*End of PHP*/

我们现在只要搜索文件上传类有大把,但是真正好用的上传类不多,下面我介绍这个文件上传类是我自己使用了很久,非常不错的一个代码,大家可参考参考一。
 代码如下 复制代码

<?php
 /**
  * 文件上传类
  */
 class uploadFile {
 
    public $max_size = '1000000';//设置上传文件大小
    public $file_name = 'date';//重命名方式代表以时间命名,其他则使用给予的名称
    public $allow_types;//允许上传的文件扩展名,不同文件类型用“|”隔开
    public $errmsg = '';//错误信息
    public $uploaded = '';//上传后的文件名(包括文件路径)
    public $save_path;//上传文件保存路径
    private $files;//提交的等待上传文件
    private $file_type = array();//文件类型
    private $ext = '';//上传文件扩展名
 
    /**
     * 构造函数,初始化类
     * @access public
     * @param string $file_name 上传后的文件名
     * @param string $save_path 上传的目标文件夹
     */
    public function __construct($save_path = './upload/',$file_name = 'date',$allow_types = '') {
        $this->file_name   = $file_name;//重命名方式代表以时间命名,其他则使用给予的名称
        $this->save_path   = (preg_match('//$/',$save_path)) ? $save_path : $save_path . '/';
        $this->allow_types = $allow_types == '' ? 'jpg|gif|png|zip|rar' : $allow_types;
    }
 
    /**
     * 上传文件
     * @access public
     * @param $files 等待上传的文件(表单传来的$_FILES[])
     * @return boolean 返回布尔值
     */
    public function upload_file($files) {
        $name = $files['name'];
        $type = $files['type'];
        $size = $files['size'];
        $tmp_name = $files['tmp_name'];
        $error = $files['error'];
 
        switch ($error) {
            case 0 : $this->errmsg = '';
                break;
            case 1 : $this->errmsg = '超过了php.ini中文件大小';
                break;
            case 2 : $this->errmsg = '超过了MAX_FILE_SIZE 选项指定的文件大小';
                break;
            case 3 : $this->errmsg = '文件只有部分被上传';
                break;
            case 4 : $this->errmsg = '没有文件被上传';
                break;
            case 5 : $this->errmsg = '上传文件大小为0';
                break;
            default : $this->errmsg = '上传文件失败!';
                break;
            }
        if($error == 0 && is_uploaded_file($tmp_name)) {
            //检测文件类型
            if($this->check_file_type($name) == FALSE){
                return FALSE;
            }
            //检测文件大小
            if($size > $this->max_size){
                $this->errmsg = '上传文件<font color=red>'.$name.'</font>太大,最大支持<font color=red>'.ceil($this->max_size/1024).'</font>kb的文件';
                return FALSE;
            }
            $this->set_save_path();//设置文件存放路径
            $new_name = $this->file_name != 'date' ? $this->file_name.'.'.$this->ext : date('YmdHis').'.'.$this->ext;//设置新文件名
            $this->uploaded = $this->save_path.$new_name;//上传后的文件名
            //移动文件
            if(move_uploaded_file($tmp_name,$this->uploaded)){
                $this->errmsg = '文件<font color=red>'.$this->uploaded.'</font>上传成功!';
                return TRUE;
            }else{
                $this->errmsg = '文件<font color=red>'.$this->uploaded.'</font>上传失败!';
                return FALSE;
            }
 
        }
    }
 
    /**
     * 检查上传文件类型
     * @access public
     * @param string $filename 等待检查的文件名
     * @return 如果检查通过返回TRUE 未通过则返回FALSE和错误消息
     */
    public function check_file_type($filename){
        $ext = $this->get_file_type($filename);
        $this->ext = $ext;
        $allow_types = explode('|',$this->allow_types);//分割允许上传的文件扩展名为数组
        //echo $ext;
        //检查上传文件扩展名是否在请允许上传的文件扩展名中
        if(in_array($ext,$allow_types)){
            return TRUE;
        }else{
            $this->errmsg = '上传文件<font color=red>'.$filename.'</font>类型错误,只支持上传<font color=red>'.str_replace('|',',',$this->allow_types).'</font>等文件类型!';
            return FALSE;
        }
    }
 
    /**
     * 取得文件类型
     * @access public
     * @param string $filename 要取得文件类型的目标文件名
     * @return string 文件类型
     */
    public function get_file_type($filename){
        $info = pathinfo($filename);
        $ext = $info['extension'];
        return $ext;
    }
 
    /**
     * 设置文件上传后的保存路径
     */
    public function set_save_path(){
        $this->save_path = (preg_match('//$/',$this->save_path)) ? $this->save_path : $this->save_path . '/';
        if(!is_dir($this->save_path)){
            //如果目录不存在,创建目录
            $this->set_dir();
        }
    }
 
 
    /**
     * 创建目录
     * @access public
     * @param string $dir 要创建目录的路径
     * @return boolean 失败时返回错误消息和FALSE
     */
    public function set_dir($dir = null){
        //检查路径是否存在
        if(!$dir){
            $dir = $this->save_path;
        }
        if(is_dir($dir)){
            $this->errmsg = '需要创建的文件夹已经存在!';
        }
        $dir = explode('/', $dir);
        foreach($dir as $v){
            if($v){
                $d .= $v . '/';
                if(!is_dir($d)){
                    $state = mkdir($d, 0777);
                    if(!$state)
                        $this->errmsg = '在创建目录<font color=red>' . $d . '时出错!';
                }
            }
        }
        return true;
    }
 }
 
/*************************************************
 * 图片处理类
 *
 * 可以对图片进行生成缩略图,打水印等操作
 * 本类默认编码为UTF8 如果要在GBK下使用请将img_mark方法中打中文字符串水印iconv注释去掉
 *
 * 由于UTF8汉字和英文字母大小(像素)不好确定,在中英文混合出现太多时可能会出现字符串偏左
 * 或偏右,请根据项目环境对get_mark_xy方法中的$strc_w = strlen($this->mark_str)*7+5进
 * 行调整
 * 需要GD库支持,为更好使用本类推荐使用GD库2.0+
 *
 * @author kickflip@php100 QQ263340607
 *************************************************/
 
 class uploadImg extends uploadFile {
 
    public $mark_str = 'kickflip@php100';  //水印字符串
    public $str_r = 0; //字符串颜色R
    public $str_g = 0; //字符串颜色G
    public $str_b = 0; //字符串颜色B
    public $mark_ttf = './upload/SIMSUN.TTC'; //水印文字字体文件(包含路径)
    public $mark_logo = './upload/logo.png';    //水印图片
    public $resize_h;//生成缩略图高
    public $resize_w;//生成缩略图宽
    public $source_img;//源图片文件
    public $dst_path = './upload/';//缩略图文件存放目录,不填则为源图片存放目录
 
    /**
     * 生成缩略图 生成后的图
     * @access public
     * @param integer $w 缩小后图片的宽(px)
     * @param integer $h 缩小后图片的高(px)
     * @param string $source_img 源图片(路径+文件名)
     */
    public function img_resized($w,$h,$source_img = NULL){
        $source_img = $source_img == NULL ? $this->uploaded : $source_img;//取得源文件的地址,如果为空则默认为上次上传的图片
        if(!is_file($source_img)) { //检查源图片是否存在
            $this->errmsg = '文件'.$source_img.'不存在';
            return FALSE;
        }
        $this->source_img = $source_img;
        $img_info = getimagesize($source_img);
        $source = $this->img_create($source_img); //创建源图片
        $this->resize_w = $w;
        $this->resize_h = $h;
        $thumb = imagecreatetruecolor($w,$h);
        imagecopyresized($thumb,$source,0,0,0,0,$w,$h,$img_info[0],$img_info[1]);//生成缩略图片
        $dst_path = $this->dst_path == '' ? $this->save_path : $this->dst_path; //取得目标文件夹路径
        $dst_path = (preg_match('//$/',$dst_path)) ? $dst_path : $dst_path . '/';//将目标文件夹后加上/
        if(!is_dir($dst_path)) $this->set_dir($dst_path); //如果不存在目标文件夹则创建
        $dst_name = $this->set_newname($source_img);
        $this->img_output($thumb,$dst_name);//输出图片
        imagedestroy($source);
        imagedestroy($thumb);
    }
 
    /**
     *打水印
     *@access public
     *@param string $source_img 源图片路径+文件名
     *@param integer $mark_type 水印类型(1为英文字符串,2为中文字符串,3为图片logo,默认为英文字符串)
     *@param integer $mark_postion 水印位置(1为左下角,2为右下角,3为左上角,4为右上角,默认为右下角);
     *@return 打上水印的图片
     */
    public function img_mark($source_img = NULL,$mark_type = 1,$mark_postion = 2) {
        $source_img = $source_img == NULL ? $this->uploaded : $source_img;//取得源文件的地址,如果为空则默认为上次上传的图片
        if(!is_file($source_img)) { //检查源图片是否存在
            $this->errmsg = '文件'.$source_img.'不存在';
            return FALSE;
        }
        $this->source_img = $source_img;
        $img_info = getimagesize($source_img);
        $source = $this->img_create($source_img); //创建源图片
        $mark_xy = $this->get_mark_xy($mark_postion);//取得水印位置
        $mark_color = imagecolorallocate($source,$this->str_r,$this->str_g,$this->str_b);
 
        switch($mark_type) {
 
            case 1 : //加英文字符串水印
            $str = $this->mark_str;
            imagestring($source,5,$mark_xy[0],$mark_xy[1],$str,$mark_color);
            $this->img_output($source,$source_img);
            break;
 
            case 2 : //加中文字符串水印
            if(!is_file($this->mark_ttf)) { //检查字体文件是否存在
                $this->errmsg = '打水印失败:字体文件'.$this->mark_ttf.'不存在!';
            return FALSE;
            }
            $str = $this->mark_str;
            //$str = iconv('gbk','utf-8',$str);//转换字符编码 如果使用GBK编码请去掉此行注释
            imagettftext($source,12,0,$mark_xy[2],$mark_xy[3],$mark_color,$this->mark_ttf,$str);
            $this->img_output($source,$source_img);
            break;
 
            case 3 : //加图片水印
            if(is_file($this->mark_logo)){  //如果存在水印logo的图片则取得logo图片的基本信息,不存在则退出
                $logo_info = getimagesize($this->mark_logo);
            }else{
                $this->errmsg = '打水印失败:logo文件'.$this->mark_logo.'不存在!';
                return FALSE;
            }
 
            $logo_info = getimagesize($this->mark_logo);
            if($logo_info[0]>$img_info[0] || $logo_info[1]>$img_info[1]) { //如果源图片小于logo大小则退出
                $this->errmsg = '打水印失败:源图片'.$this->source_img.'比'.$this->mark_logo.'小!';
                return FALSE;
            }
 
            $logo = $this->img_create($this->mark_logo);
            imagecopy ( $source, $logo, $mark_xy[4], $mark_xy[5], 0, 0, $logo_info[0], $logo_info[1]);
            $this->img_output($source,$source_img);
            break;
 
            default: //其它则为文字图片
            $str = $this->mark_str;
            imagestring($source,5,$mark_xy[0],$mark_xy[1],$str,$mark_color);
            $this->img_output($source,$source_img);
            break;
        }
        imagedestroy($source);
    }
 
    /**
     * 取得水印位置
     * @access private
     * @param integer $mark_postion 水印的位置(1为左下角,2为右下角,3为左上角,4为右上角,其它为右下角)
     * @return array $mark_xy 水印位置的坐标(索引0为英文字符串水印坐标X,索引1为英文字符串水印坐标Y,
     * 索引2为中文字符串水印坐标X,索引3为中文字符串水印坐标Y,索引4为水印图片坐标X,索引5为水印图片坐标Y)
     */
    private function get_mark_xy($mark_postion){
        $img_info = getimagesize($this->source_img);
 
        $stre_w = strlen($this->mark_str)*9+5 ; //水印英文字符串的长度(px)(5号字的英文字符大小约为9px 为了美观再加5px)
        //(12号字的中文字符大小为12px,在utf8里一个汉字长度为3个字节一个字节4px 而一个英文字符长度一个字节大小大约为9px
        // 为了在中英文混合的情况下显示完全 设它的长度为字节数*7px)
        $strc_w = strlen($this->mark_str)*7+5 ; //水印中文字符串的长度(px)
 
        if(is_file($this->mark_logo)){ //如果存在水印logo的图片则取得logo图片的基本信息
            $logo_info = getimagesize($this->mark_logo);
        }
 
        //由于imagestring函数和imagettftext函数中对于字符串开始位置不同所以英文和中文字符串的Y位置也有所不同
        //imagestring函数是从文字的左上角为参照 imagettftext函数是从文字左下角为参照
        switch($mark_postion){
 
            case 1: //位置左下角
            $mark_xy[0] = 5; //水印英文字符串坐标X
            $mark_xy[1] = $img_info[1]-20;//水印英文字符串坐标Y
            $mark_xy[2] = 5; //水印中文字符串坐标X
            $mark_xy[3] = $img_info[1]-5;//水印中文字符串坐标Y
            $mark_xy[4] = 5;//水印图片坐标X
            $mark_xy[5] = $img_info[1]-$logo_info[1]-5;//水印图片坐标Y
            break;
 
            case 2: //位置右下角
            $mark_xy[0] = $img_info[0]-$stre_w; //水印英文字符串坐标X
            $mark_xy[1] = $img_info[1]-20;//水印英文字符串坐标Y
            $mark_xy[2] = $img_info[0]-$strc_w; //水印中文字符串坐标X
            $mark_xy[3] = $img_info[1]-5;//水印中文字符串坐标Y
            $mark_xy[4] = $img_info[0]-$logo_info[0]-5;//水印图片坐标X
            $mark_xy[5] = $img_info[1]-$logo_info[1]-5;//水印图片坐标Y
            break;
 
            case 3: //位置左上角
            $mark_xy[0] = 5; //水印英文字符串坐标X
            $mark_xy[1] = 5;//水印英文字符串坐标Y
            $mark_xy[2] = 5; //水印中文字符串坐标X
            $mark_xy[3] = 15;//水印中文字符串坐标Y
            $mark_xy[4] = 5;//水印图片坐标X
            $mark_xy[5] = 5;//水印图片坐标Y
            break;
 
            case 4: //位置右上角
            $mark_xy[0] = $img_info[0]-$stre_w; //水印英文字符串坐标X
            $mark_xy[1] = 5;//水印英文字符串坐标Y
            $mark_xy[2] = $img_info[0]-$strc_w; //水印中文字符串坐标X
            $mark_xy[3] = 15;//水印中文字符串坐标Y
            $mark_xy[4] = $img_info[0]-$logo_info[0]-5;//水印图片坐标X
            $mark_xy[5] = 5;//水印图片坐标Y
            break;
 
            default : //其它默认为右下角
            $mark_xy[0] = $img_info[0]-$stre_w; //水印英文字符串坐标X
            $mark_xy[1] = $img_info[1]-5;//水印英文字符串坐标Y
            $mark_xy[2] = $img_info[0]-$strc_w; //水印中文字符串坐标X
            $mark_xy[3] = $img_info[1]-15;//水印中文字符串坐标Y
            $mark_xy[4] = $img_info[0]-$logo_info[0]-5;//水印图片坐标X
            $mark_xy[5] = $img_info[1]-$logo_info[1]-5;//水印图片坐标Y
            break;
        }
        return $mark_xy;
    }
 
    /**
     * 创建源图片
     * @access private
     * @param string $source_img 源图片(路径+文件名)
     * @return img 从目标文件新建的图像
     */
    private function img_create($source_img) {
        $info = getimagesize($source_img);
        switch ($info[2]){
            case 1:
            if(!function_exists('imagecreatefromgif')){
                $source = @imagecreatefromjpeg($source_img);
            }else{
                $source = @imagecreatefromgif($source_img);
            }
            break;
            case 2:
            $source = @imagecreatefromjpeg($source_img);
            break;
            case 3:
            $source = @imagecreatefrompng($source_img);
            break;
            case 6:
            $source = @imagecreatefromwbmp($source_img);
            break;
            default:
            $source = FALSE;
            break;
        }
        return $source;
    }
 
 /**
  * 重命名图片
  * @access private
  * @param string $source_img 源图片路径+文件名
  * @return string $dst_name 重命名后的图片名(路径+文件名)
  */
 private function set_newname($sourse_img) {
    $info = pathinfo($sourse_img);
    $new_name = $this->resize_w.'_'.$this->resize_h.'_'.$info['basename'];//将文件名修改为:宽_高_文件名
    if($this->dst_path == ''){ //如果存放缩略图路径为空则默认为源文件同文件夹
        $dst_name = str_replace($info['basename'],$new_name,$sourse_img);
    }else{
        $dst_name = $this->dst_path.$new_name;
    }
    return $dst_name;
 }
 
 /**
  * 输出图片
  * @access private
  * @param $im 处理后的图片
  * @param $dst_name 输出后的的图片名(路径+文件名)
  * @return 输出图片
  */
 public function img_output($im,$dst_name) {
    $info = getimagesize($this->source_img);
    switch ($info[2]){
            case 1:
            if(!function_exists('imagegif')){
                imagejpeg($im,$dst_name);
            }else{
                imagegif($im, $dst_name);
            }
            break;
            case 2:
            imagejpeg($im,$dst_name);
            break;
            case 3:
            imagepng($im,$dst_name);
            break;
            case 6:
            imagewbmp($im,$dst_name);
            break;
        }
 }
 
 }
?>

使用方法

 代码如下 复制代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>上传文件</title></head><body leftmargin="0" topmargin="0"><table cellpadding="2" cellspacing="1" border="0" height="100%" align="left"><form action='wend.php?action=upload'  method='post' enctype='multipart/form-data'><tr ><td  valign='middle'><input type='file' name='uploadfile'><input name='submit' type='submit' value='上传'></td></tr></form></table</body></html>

php处理文件

调用上面的类文件,然后再如下操作

 代码如下 复制代码

$action = addslashes($_GET['action']);
if( $action =="udd")
{
 $state=uploadfile('uploadfile');
 //echo $state['err'];exit;
 if($state['err']){
  die('<script>alert("上传出错:'.$state['err'].'");history.go(-1);</script>');
 }
 else
 {
  echo '文件己上传!<a href="upp.php">删除重传</a>';
  
 }


}
else{
 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
 echo '<html xmlns="http://www.w3.org/1999/xhtml">';
 echo '<head>';
 echo '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />';
 echo '<title>上传文件</title>';
 //echo "<meta http-equiv="content-type" content="text/html; charset=gb2312">";
 echo '</head>';
 echo "<body leftmargin="0" topmargin="0">";
 echo "<table cellpadding="2" cellspacing="1" border="0" height="100%" align="left">";
 echo "<form action='abc.php?action=udd'  method='post' enctype='multipart/form-data'>";
 echo "<tr ><td  valign='middle'>";
 echo "<input type='file' name='uploadfile'>";
 echo "<input name='submit' type='submit' value='上传'>";
 echo "</td></tr>";
 echo "</form>";
 echo "</table";
 echo "</body>";
 echo '</html>';
}

本文章提供这款php验证码生成类灵活好用,用户可以定义各个成员 有宽、高、画布、字数、类型、画类型同时我们只要修改 $Type就可以定义生成的是纯数字 , 纯小写字母,大小写数字混合,有需要的朋友可参考。
 代码如下 复制代码

<?php
class Code{

// 1. 定义各个成员 有宽、高、画布、字数、类型、画类型

private $width; //宽度
private $height; //高度
private $num; //验证码字数
private $imgType; //生成图片类型
private $Type; //字串类型 1,2,3 三个选项 1 纯数字 2 纯小写字母 3 大小写数字混合
private $hb; //画布
public $codestr; // 验证码字串

public function __construct($height=20,$num=4,$imgType="jpeg",$Type=1){
$this->width = $num*20;
$this->height = $height;
$this->num = $num;
$this->imgType = $imgType;
$this->Type = $Type;
$this->codestr = $this->codestr();
$this->zuhe();
}

// 2. 定义随机获取字符串函数
private function codestr(){
switch($this->Type){

case 1: // 类型为1 获取1-9随机数
$str = implode("",array_rand(range(0,9),$this->num));
break;
case 2: // 类型为2 获取a-z随机小写字母
$str = implode("",array_rand(array_flip(range(a,z)),$this->num));
break;
case 3: // 类型为3 获取数字,小写字母,大写字母 混合
for($i=0;$i<$this->num;$i++){
$m = rand(0,2);
switch($m){
case 0:
$o = rand(48,57);
break;
case 1:
$o = rand(65,90);
break;
case 2:
$o = rand(97,122);
break;
}
$str .= sprintf("%c",$o);
}
break;
}


return $str;
}


// 3. 初始化画布图像资源
private function Hb(){
$this->hb = imagecreatetruecolor($this->width,$this->height);
}

// 4. 生成背景颜色
private function Bg(){
return imagecolorallocate($this->hb,rand(130,250),rand(130,250),rand(130,250));
}

// 5. 生成字体颜色
private function Font(){
return imagecolorallocate($this->hb,rand(0,100),rand(0,100),rand(0,100));
}

// 6. 填充背景颜色
private function BgColor(){
imagefilledrectangle($this->hb,0,0,$this->width,$this->height,$this->Bg());
}

// 7. 干扰点
private function ganrao(){
$sum=floor(($this->width)*($this->height)/3);
for($i=0;$i<$sum;$i++){
imagesetpixel($this->hb,rand(0,$this->width),rand(0,$this->height),$this->Bg());
}
}

// 8. 随机直线 弧线
private function huxian(){
for($i=0;$i<$this->num;$i++){
imageArc($this->hb,rand(0,$this->width),rand(0,$this->height),rand(0,$this->width),rand(0,$this->height),rand(0,360),rand(0,360),$this->Bg());
}
}

// 9. 写字
private function xiezi(){
for($i=0;$i<$this->num;$i++){
$x=ceil($this->width/$this->num)*$i;
$y=rand(1,$this->height-15);
imagechar($this->hb,5,$x+4,$y,$this->codestr[$i],$this->Font());
}
}

// 10. 输出
private function OutImg(){
$shuchu="image".$this->imgType;
$header="Content-type:image/".$this->imgType;
if(function_exists($shuchu)){
header($header);
$shuchu($this->hb);
}else{
exit("GD库没有此类图像");
}
}

// 11. 拼装
private function zuhe(){
$this->Hb();
$this->BgColor();
$this->ganrao();
$this->huxian();
$this->xiezi();
$this->OutImg();
}

public function getCodeStr(){
return $this->codestr;
}
}
?>

在php中我们经常使用写一些简单的采集功能,这样可以自动把远程服务器的图片或资源直接采集保存到本地服务器中,下面我来给大家详细介绍远程图片并把它保存到本地几种方法。

例1

 代码如下 复制代码

/*
*功能:php多种方式完美实现下载远程图片保存到本地
*参数:文件url,保存文件名称,使用的下载方式
*当保存文件名称为空时则使用远程文件原来的名称
*/
function getImage($url,$filename='',$type=0){
    if($url==''){return false;}
    if($filename==''){
        $ext=strrchr($url,'.');
        if($ext!='.gif' && $ext!='.jpg'){return false;}
        $filename=time().$ext;
    }
    //文件保存路径
    if($type){
  $ch=curl_init();
  $timeout=5;
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $img=curl_exec($ch);
  curl_close($ch);
    }else{
     ob_start();
     readfile($url);
     $img=ob_get_contents();
     ob_end_clean();
    }
    $size=strlen($img);
    //文件大小
    $fp2=@fopen($filename,'a');
    fwrite($fp2,$img);
    fclose($fp2);
    return $filename;
}

例2

 代码如下 复制代码

<?php

//
// Function: 获取远程图片并把它保存到本地
//
//
//   确定您有把文件写入本地服务器的权限
// 
//
// 变量说明:
// $url 是远程图片的完整URL地址,不能为空。
// $filename 是可选变量: 如果为空,本地文件名将基于时间和日期
// 自动生成.

function GrabImage($url,$filename="") {
   if($url==""):return false;endif;

   if($filename=="") {
     $ext=strrchr($url,".");
     if($ext!=".gif" && $ext!=".jpg"):return false;endif;
     $filename=date("dMYHis").$ext;
   }

   ob_start();
   readfile($url);
   $img = ob_get_contents();
   ob_end_clean();
   $size = strlen($img);

   $fp2=@fopen($filename, "a");
   fwrite($fp2,$img);
   fclose($fp2);

   return $filename;
}


$img=GrabImage("http://www.111cn.net","");
if($img):echo '<pre><img src="'.$img.'"></pre>';else:echo "false";endif;  

?>


dedecms中的:

 

 代码如下 复制代码
if(!empty($saveremoteimg))
         {
                 $body = stripslashes($body);
                 $img_array = array();
                 preg_match_all("/(src|SRC)=["|'| ]{0,}(http://(.*).(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
                 $img_array = array_unique($img_array[2]);
                 set_time_limit(0);
                 $imgUrl = $img_dir."/".strftime("%Y%m%d",time());
                 $imgPath = $base_dir.$imgUrl;
                 $milliSecond = strftime("%H%M%S",time());
                 if(!is_dir($imgPath)) @mkdir($imgPath,0777);
                 foreach($img_array as $key =>$value)
                 {
                         $value = trim($value);
                         $get_file = @file_get_contents($value);
                         $rndFileName = $imgPath."/".$milliSecond.$key.".".substr($value,-3,3);
                         $fileurl = $imgUrl."/".$milliSecond.$key.".".substr($value,-3,3);
                         if($get_file)
                         {
                                 $fp = @fopen($rndFileName,"w");
                                 @fwrite($fp,$get_file);
                                 @fclose($fp);
                         }
                         $body = ereg_replace($value,$fileurl,$body);
                 }
                 $body = addslashes($body);
         }
?>

例4

 代码如下 复制代码

<?php
//
// Function: 获取远程图片并把它保存到本地
//
//
// 确定您有把文件写入本地服务器的权限
//
//
// 变量说明:
// $url 是远程图片的完整URL地址,不能为空。
// $filename 是可选变量: 如果为空,本地文件名将基于时间和日期// 自动生成.
function GrabImage($url,$filename='') {
if($url==''):return false;endif;
if($filename=='') {
$ext=strrchr($url,'.');
if($ext!='.gif' && $ext!='.jpg'):return false;endif;$filename=date('dMYHis').$ext;
}
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
$fp2=@fopen($filename, 'a');
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
$img=GrabImage('http://www.ccc.cc/static/image/common/logo.png','');
if($img){echo '<pre><img src='.$img.'></pre>';}else{echo 'false';}
?>

[!--infotagslink--]

相关文章

  • php读取zip文件(删除文件,提取文件,增加文件)实例

    下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
  • Jupyter Notebook读取csv文件出现的问题及解决

    这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06
  • Photoshop打开PSD文件空白怎么解决

    有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
  • 解决python 使用openpyxl读写大文件的坑

    这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
  • C#实现HTTP下载文件的方法

    这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • SpringBoot实现excel文件生成和下载

    这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
  • C#操作本地文件及保存文件到数据库的基本方法总结

    C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
  • php无刷新利用iframe实现页面无刷新上传文件(1/2)

    利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25
  • Php文件上传类class.upload.php用法示例

    本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
  • php批量替换内容或指定目录下所有文件内容

    要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
  • PHP文件上传一些小收获

    又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
  • jQuery实现简单的文件上传进度条效果

    本文实例讲述了jQuery实现文件上传进度条效果的代码。分享给大家供大家参考。具体如下: 运行效果截图如下:具体代码如下:<!DOCTYPE html><html><head><meta charset="utf-8"><title>upload</title><link rel="stylesheet...2015-11-24
  • AI源文件转photoshop图像变模糊问题解决教程

    今天小编在这里就来给photoshop的这一款软件的使用者们来说下AI源文件转photoshop图像变模糊问题的解决教程,各位想知道具体解决方法的使用者们,那么下面就快来跟着小编...2016-09-14
  • C++万能库头文件在vs中的安装步骤(图文)

    这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
  • Zend studio文件注释模板设置方法

    步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
  • php文件上传你必须知道的几点

    本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
  • ant design中upload组件上传大文件,显示进度条进度的实例

    这篇文章主要介绍了ant design中upload组件上传大文件,显示进度条进度的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-29
  • C#使用StreamWriter写入文件的方法

    这篇文章主要介绍了C#使用StreamWriter写入文件的方法,涉及C#中StreamWriter类操作文件的相关技巧,需要的朋友可以参考下...2020-06-25
  • php实现文件下载实例分享

    举一个案例:复制代码 代码如下:<?phpclass Downfile { function downserver($file_name){$file_path = "./img/".$file_name;//转码,文件名转为gb2312解决中文乱码$file_name = iconv("utf-8","gb2312",$file_name...2014-06-07
  • C#路径,文件,目录及IO常见操作汇总

    这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25