php curl模拟post请求提交数据例子总结

 更新时间:2016年11月25日 16:21  点击:1814
在php中要模拟post请求数据提交我们会使用到curl函数,下面我来给大家举几个curl模拟post请求提交数据例子有需要的朋友可参考参考。

注意:curl函数在php中默认是不被支持的,如果需要使用curl函数我们需在改一改你的php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了

例1

 代码如下 复制代码

<?php
$uri = "http://tanteng.duapp.com/test.php";
// 参数数组
$data = array (
        'name' => 'tanteng'
// 'password' => 'password'
);
 
$ch = curl_init ();
// print_r($ch);
curl_setopt ( $ch, CURLOPT_URL, $uri );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
$return = curl_exec ( $ch );
curl_close ( $ch );
 
print_r($return);

接受php页面远程服务器:

<?php
if(isset($_POST['name'])){
    if(!empty($_POST['name'])){
        echo '您好,',$_POST['name'].'!';
    }
}
?>

例2

用CURL模拟POST请求抓取邮编与地址

完整代码:

 代码如下 复制代码

#!/usr/local/php/bin/php
<?php
$runtime = new runtime ();
$runtime->start ();


$cookie_jar = tempnam('/tmp','cookie');

 


$filename = $argv[1];
$start_num= $argv[2];
$end_num  = $argv[3];

 


for($i=$start_num; $i<$end_num; $i++){
    $zip = sprintf('6s',$i);


    $fields_post = array(
            'postcode' => $zip,
            'queryKind' => 2,
            'reqCode' => 'gotoSearch',
            'search_button.x'=>37,
            'search_button.y'=>12
            );


    $fields_string = http_build_query ( $fields_post, '&' );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "URL?reqCode=gotoSearch&queryKind=2&postcode=".$zip);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120 );
    curl_setopt($ch, CURLOPT_REFERER, $refer );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login );
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar );
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar );
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_POST, 1); // 发送一个常规的Post请求
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string );


    $data = curl_exec($ch);
    preg_match_all('/id="table1">[s]*?<tr>[s]*?<td class="maintext">[sS]*?</td>[s]*?</tr>/', $data, $matches);
    if (!$handle = fopen($filename, 'a+')) {
        echo "不能打开文件 $filename";
        echo "n";
        exit;
    }


    if (fwrite($handle, $matches[0][1]) === FALSE) {
        echo "不能写入到文件 $filename";
        echo "n";
        exit;
    }


    echo "成功地将 $somecontent 写入到文件$filename";
    echo "n";


    fclose($handle);
    curl_close($ch);
}

 


class runtime
{
    var $StartTime = 0;
    var $StopTime = 0;
    function get_microtime()
    {
        list($usec,$sec)=explode(' ',microtime());return((float)$usec+(float)$sec);
    }
    function start()
    {
        $this->StartTime=$this->get_microtime();
    }
    function stop(){
        $this->StopTime=$this->get_microtime();
    }
    function spent()
    {
        return ($this->StopTime-$this->StartTime);
    }
}

 


$runtime->stop ();


$con = 'Processed in'.$runtime->spent().'seconds';
echo 'Processed in'. $runtime->spent().'seconds';

模拟POST请求 提交数据或上传文件 .

.

 代码如下 复制代码

http://www.a.com/a.php

发送POST请求

function execUpload(){


$file = '/doucment/Readme.txt';
$ch = curl_init();
$post_data = array(
    'loginfield' => 'username',
    'username' => 'ybb',
    'password' => '123456',
'file' => '@d:usrwwwtranslatedocumentReadme.txt'
);
curl_setopt($ch, CURLOPT_HEADER, false);
//启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch,CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_URL, 'http://www.b.com/handleUpload.php');
$info= curl_exec($ch);
curl_close($ch);
  
print_r($info);

}

2.http://www.b.com/handleUpload.php

function handleUpload(){
print_r($_POST);
echo '===file upload info:';
print_r($_FILES);
}

■cURL 函数

■curl_close — 关闭一个cURL会话
■curl_copy_handle — 复制一个cURL句柄和它的所有选项
■curl_errno — 返回最后一次的错误号
■curl_error — 返回一个保护当前会话最近一次错误的字符串
■curl_exec — 执行一个cURL会话
■curl_getinfo — 获取一个cURL连接资源句柄的信息
■curl_init — 初始化一个cURL会话
■curl_multi_add_handle — 向curl批处理会话中添加单独的curl句柄
■curl_multi_close — 关闭一组cURL句柄
■curl_multi_exec — 运行当前 cURL 句柄的子连接
■curl_multi_getcontent — 如果设置了CURLOPT_RETURNTRANSFER,则返回获取的输出的文本流
■curl_multi_info_read — 获取当前解析的cURL的相关传输信息
■curl_multi_init — 返回一个新cURL批处理句柄
■curl_multi_remove_handle — 移除curl批处理句柄资源中的某个句柄资源
■curl_multi_select — 等待所有cURL批处理中的活动连接
■curl_setopt_array — 为cURL传输会话批量设置选项
■curl_setopt — 设置一个cURL传输选项
■curl_version — 获取cURL版本信息

我们会看到很多的网站不但有设置首页,加入收藏同时还有一个加和到桌面快捷方式的功能,下面我来给大家介绍网页创建快捷方式到桌面多种方法介绍。有需要的朋友可参考。

最简单的js实现方法

 代码如下 复制代码

<script language="JavaScript"> 

function toDesktop(sUrl,sName){ 

try 

var WshShell = new ActiveXObject("WScript.Shell"); 

var oUrlLink = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop") + "\" + sName + ".url"); 

oUrlLink.TargetPath = sUrl; 

oUrlLink.Save(); 

catch(e) 

alert("请点击弹出对话框的:是 "); 

</script> 

<input name="btn" type="button" id="btn" value="把百度创建快捷方式到桌面" onClick="toDesktop('http://www.111cn.net/','百度一下,你就知道!')"> 

<input name="btn" type="button" id="btn" value="C盘" onClick="toDesktop('file://C:','C盘')"> 

不足:这样做如果浏览器做了安全设置我们是不能使用上面的方法的。

写php程序的朋友可能也知道一种办法,代码如下

 代码如下 复制代码

<?php 

$Shortcut = "[InternetShortcut] 

URL=http://www.111cn.net 

IconFile=http://www.111cn.net/favicon.ico 

IconIndex=0 

HotKey=1613 

IDList= 

[{000214A0-0000-0000-C000-000000000046}] 

Prop3=19,2"; 

header("Content-Type: application/octet-stream"); 

header("Content-Disposition: attachment; filename=蜕变无忧.url"); 

echo $Shortcut; 

?> 


<a href="">发送到桌面</a> 


asp.net程序员可能也知道如下代码

 

 代码如下 复制代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class CreateShortcut : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 创建快捷方式
/// </summary>
/// <param name="Title">标题</param>
/// <param name="URL">URL地址</param>
private void CreateShortcut(string Title, string URL)
{
string strFavoriteFolder;
// “收藏夹”中 创建 IE 快捷方式
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
CreateShortcutFile(Title, URL, strFavoriteFolder);
// “ 桌面 ”中 创建 IE 快捷方式
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
CreateShortcutFile(Title, URL, strFavoriteFolder);
// “ 链接 ”中 创建 IE 快捷方式
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\链接";
CreateShortcutFile(Title, URL, strFavoriteFolder);
//「开始」菜单中 创建 IE 快捷方式
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
CreateShortcutFile(Title, URL, strFavoriteFolder);
}
/// <summary>
/// 创建快捷方式
/// </summary>
/// <param name="Title">标题</param>
/// <param name="URL">URL地址</param>
/// <param name="SpecialFolder">特殊文件夹</param>
private void CreateShortcutFile(string Title, string URL, string SpecialFolder)
{
// Create shortcut file, based on Title
System.IO.StreamWriter objWriter = System.IO.File.CreateText(SpecialFolder + "\" + Title + ".url");
// Write URL to file
objWriter.WriteLine("[InternetShortcut]");
objWriter.WriteLine("URL=" + URL);
// Close file
objWriter.Close();
}
private void btnShortcut_Click(object sender, System.EventArgs e)
{
CreateShortcut("脚本之家", http://www.111cn.net);
}
}
在php中错误处理的方法有很多,特别是到了php5之后还提供了专门的php处理类,下面我收藏了关于PHP错误处理一些方法与程序分享给大家。

在程序中直接判断

基本的错误处理:使用 die() 函数
第一个例子展示了一个打开文本文件的简单脚本:

 代码如下 复制代码

<?php
$file=fopen("welcome.txt","r");
?>

如果文件不存在,您会获得类似这样的错误:

Warning: fopen(welcome.txt) [function.fopen]: failed to open stream:
No such file or directory in C:webfoldertest.php on line 2

更多详细的

 代码如下 复制代码

<?php
   
    //打开一个文件 未做任何处理
    //$fp =fopen("aa.txt","r");
    //echo "OK";

    //处理:判断文件是否存在 file_exists
/*
    if(!file_exists("aa.txt")){
        echo "文件不存在";
        //不存在就退出
        exit();  //退出后,下面面的代码就不执行了
    }else{
        $fp =fopen("aa.txt","r");
        //...操作完之后 关闭
        fclose($fp);

    }

    echo "OK";
*/
    //PHP处理错误的3种方法

    //第一种:使用简单的die语句

/*    if(!file_exists("aa.txt")){
   
        die("文件不存在。。。"); //不存在就直接退出
    }else{
        $fp =fopen("aa.txt","r");
        //...操作完之后 关闭
        fclose($fp);

    }

    echo "OK";
*/
    //更简单的方式
    file_exists("aa.txt") or die("文件不存在");


?>

第二种:错误处理器 错误级别 处理错误方式

 代码如下 复制代码

<?php

    //
    /*
    使用error_function(error_level,error_message,
    error_file,error_line,error_context)
    该函数必须有能力处理至少两个参数 (error level 和 error message),
    但是可以接受最多五个参数(可选的:file, line-number 以及 error context):

    */

    //改写set_error_handler方法
    //如果出现 E_WARNING 这个错误就调用my_error 处理方法
    set_error_handler("my_error",E_WARNING);
    set_error_handler("my_error2",E_USER_ERROR);
    //设置中国对应的时区
    date_default_timezone_set('PRC');
   
    function my_error($errno,$errmes){
       
        echo "<font size='5' color='red' >$errno</font>"; //输出错误报告级别
        echo "错误信息是:".$errmes;
        exit();
    }

    function my_error2($errno,$errmes){
       
        //echo "错误信息是:".$errno,$errmes;
        //exit();
        //把错误信息输入到文本中保存已备查看 使用到error_log()函数
        $message ="错误信息是:".$errno." ".$errmes;
        error_log(date("Y-m-d G:i:s")."---".$message."rn",3,"myerror.txt"); // rn 表示换行
    }

    //打开一个文件 未做任何处理

    //$fp =fopen("aa.txt","r");
    //echo "OK";

    //使用自定义错误 要添加触发器 这个trigger_error()函数来指定调用自定义的错误
    $age=200;
    if($age>150){
        //echo "年龄过大";
        //调用触发器 同时指定错误级别 这里需要查看帮助文档
        trigger_error("不好了出大问题了",E_USER_ERROR);
        //exit();
    }


?>

PHP 异常处理

PHP 5 提供了一种新的面向对象的错误处理方法


如果异常没有被捕获,而且又没用使用 set_exception_handler() 作相应的处理的话,那么将发生一个严重的错误(致命错误),并且输出 "Uncaught Exception" (未捕获异常)的错误消息。

让我们尝试抛出一个异常,同时不去捕获它:

 代码如下 复制代码

<?php
//create function with an exception
function checkNum($number)
 {
 if($number>1)
  {
  throw new Exception("Value must be 1 or below");
  }
 return true;
 }

//trigger exception
checkNum(2);
?>

上面的代码会获得类似这样的一个错误:

Fatal error: Uncaught exception 'Exception'
with message 'Value must be 1 or below' in C:webfoldertest.php:6
Stack trace: #0 C:webfoldertest.php(12):
checkNum(28) #1 {main} thrown in C:webfoldertest.php on line 6Try, throw 和 catch
要避免上面例子出现的错误,我们需要创建适当的代码来处理异常。

处理处理程序应当包括:

1.Try - 使用异常的函数应该位于 "try" 代码块内。如果没有触发异常,则代码将照常继续执行。但是如果异常被触发,会抛出一个异常。
2.Throw - 这里规定如何触发异常。每一个 "throw" 必须对应至少一个 "catch"
3.Catch - "catch" 代码块会捕获异常,并创建一个包含异常信息的对象
让我们触发一个异常:

 代码如下 复制代码

<?php
//创建可抛出一个异常的函数
function checkNum($number)
 {
 if($number>1)
  {
  throw new Exception("Value must be 1 or below");
  }
 return true;
 }

//在 "try" 代码块中触发异常
try
 {
 checkNum(2);
 //If the exception is thrown, this text will not be shown
 echo 'If you see this, the number is 1 or below';
 }

//捕获异常
catch(Exception $e)
 {
 echo 'Message: ' .$e->getMessage();
 }
?>

上面代码将获得类似这样一个错误:

Message: Value must be 1 or below

创建一个自定义的 Exception 类
创建自定义的异常处理程序非常简单。我们简单地创建了一个专门的类,当 PHP 中发生异常时,可调用其函数。该类必须是 exception 类的一个扩展。

这个自定义的 exception 类继承了 PHP 的 exception 类的所有属性,您可向其添加自定义的函数。

我们开始创建 exception 类:

 代码如下 复制代码

<?php
class customException extends Exception
 {
 public function errorMessage()
  {
  //error message
  $errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile()
  .': <b>'.$this->getMessage().'</b> is not a valid E-Mail address';
  return $errorMsg;
  }
 }

$email = "someone@example...com";

try
 {
 //check if
 if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE)
  {
  //throw exception if email is not valid
  throw new customException($email);
  }
 }

catch (customException $e)
 {
 //display custom message
 echo $e->errorMessage();
 }
?>

这个新的类是旧的 exception 类的副本,外加 errorMessage() 函数。正因为它是旧类的副本,因此它从旧类继承了属性和方法,我们可以使用 exception 类的方法,比如 getLine() 、 getFile() 以及 getMessage()。

本文章来给大家介绍一个利用PHP CURL模拟POST提交XML数据,因为接受方只接受xml数据所以我就写了一个,下面分享给各位朋友,有需要的朋友可参考。
 代码如下 复制代码


$url = "http://www.111cn.net/ login";
<!--?xml version="1.0"?--> 
 $ch = curl_init();
$header[] = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $url); //定义表单提交地址
curl_setopt($ch, CURLOPT_POST, 1);   //定义提交类型 1:POST ;0:GET
curl_setopt($ch, CURLOPT_HEADER, 1); //定义是否显示状态头 1:显示 ; 0:不显示
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//定义请求类型
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//定义是否直接输出返回流
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //定义提交的数据,这里是XML文件
 curl_close($ch);//关闭

再来介绍一个POST表单提交的案例

 代码如下 复制代码

//首先要引用这个类
include("/data/tools/pooy/Snoopy/Snoopy.class.php");
$snoopy = new Snoopy;
//$Parameters这个是要提交的数组
$Parameters["username"] = "user";
$Parameters["pass"] = "pass";
$file = "/test/test.jpg";
$serviceUrl = "http://www.test.com/fileProcess.php";
$postfiles["image"] = $file; //$filename上传文件相对路径 例如"upload/taoav.jpg";image/jpg
$snoopy->_submit_type = "multipart/form-data"; //设定submit类型
$snoopy->submit($serviceUrl,$Parameters,$postfiles);

本程序可以快速的实现把我们的文件利用php压缩类压缩成我们想的zip,或者rar 的压缩包,后缀名可以自定义哦, 压缩算法是来自国外一个网站抄的。

首先实例化,然后传参。两个参数。第一个关于你文件地址的一个Array。第二个是要你要保存的压缩包文件的绝对地址。

For example:

 代码如下 复制代码
        $zipfiles =array("/root/pooy/test1.txt","/root/pooy/test2.txt");
        $z = new PHPZip();
        //$randomstr = random(8);
        $zipfile = TEMP."/photocome_".$groupid.".zip";

        $z->Zip($zipfiles, $zipfile);

//添加文件列表PHP的ZIP压缩类如下:

 代码如下 复制代码

<?php
#
# PHPZip v1.2 by Sext (sext@neud.net) 2002-11-18
#     (Changed: 2003-03-01)
#
# Makes zip archive
#
# Based on "Zip file creation class", uses zLib
#
#

class PHPZip
{
    function Zip($dir, $zipfilename)
    {
        if (@function_exists('gzcompress'))
        {   
            $curdir = getcwd();
            if (is_array($dir))
            {
                    $filelist = $dir;
            }
            else
            {
                $filelist = $this -> GetFileList($dir);
            }

            if ((!empty($dir))&&(!is_array($dir))&&(file_exists($dir))) chdir($dir);
            else chdir($curdir);

            if (count($filelist)>0)
            {
                foreach($filelist as $filename)
                {
                    if (is_file($filename))
                    {
                        $fd = fopen ($filename, "r");
                        $content = fread ($fd, filesize ($filename));
                        fclose ($fd);

                        if (is_array($dir)) $filename = basename($filename);
                        $this -> addFile($content, $filename);
                    }
                }
                $out = $this -> file();

                chdir($curdir);
                $fp = fopen($zipfilename, "w");
                fwrite($fp, $out, strlen($out));
                fclose($fp);
            }
            return 1;
        }
        else return 0;
    }

    function GetFileList($dir)
    {
        if (file_exists($dir))
        {
            $args = func_get_args();
            $pref = $args[1];

            $dh = opendir($dir);
            while($files = readdir($dh))
            {
                if (($files!=".")&&($files!=".."))
                {
                    if (is_dir($dir.$files))
                    {
                        $curdir = getcwd();
                        chdir($dir.$files);
                        $file = array_merge($file, $this -> GetFileList("", "$pref$files/"));
                        chdir($curdir);
                    }
                    else $file[]=$pref.$files;
                }
            }
            closedir($dh);
        }
        return $file;
    }

    var $datasec      = array();
    var $ctrl_dir     = array();
    var $eof_ctrl_dir = "x50x4bx05x06x00x00x00x00";
    var $old_offset   = 0;

    /**
     * Converts an Unix timestamp to a four byte DOS date and time format (date
     * in high two bytes, time in low two bytes allowing magnitude comparison).
     *
     * @param  integer  the current Unix timestamp
     *
     * @return integer  the current date in a four byte DOS format
     *
     * @access private
     */
    function unix2DosTime($unixtime = 0) {
        $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);

        if ($timearray['year'] < 1980) {
            $timearray['year']    = 1980;
            $timearray['mon']     = 1;
            $timearray['mday']    = 1;
            $timearray['hours']   = 0;
            $timearray['minutes'] = 0;
            $timearray['seconds'] = 0;
        } // end if

        return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
                ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
    } // end of the 'unix2DosTime()' method

    /**
     * Adds "file" to archive
     *
     * @param  string   file contents
     * @param  string   name of the file in the archive (may contains the path)
     * @param  integer  the current timestamp
     *
     * @access public
     */
    function addFile($data, $name, $time = 0)
    {
        $name     = str_replace('\', '/', $name);

        $dtime    = dechex($this->unix2DosTime($time));
        $hexdtime = 'x' . $dtime[6] . $dtime[7]
                  . 'x' . $dtime[4] . $dtime[5]
                  . 'x' . $dtime[2] . $dtime[3]
                  . 'x' . $dtime[0] . $dtime[1];
        eval('$hexdtime = "' . $hexdtime . '";');

        $fr   = "x50x4bx03x04";
        $fr   .= "x14x00";            // ver needed to extract
        $fr   .= "x00x00";            // gen purpose bit flag
        $fr   .= "x08x00";            // compression method
        $fr   .= $hexdtime;             // last mod time and date

        // "local file header" segment
        $unc_len = strlen($data);
        $crc     = crc32($data);
        $zdata   = gzcompress($data);
        $c_len   = strlen($zdata);
        $zdata   = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
        $fr      .= pack('V', $crc);             // crc32
        $fr      .= pack('V', $c_len);           // compressed filesize
        $fr      .= pack('V', $unc_len);         // uncompressed filesize
        $fr      .= pack('v', strlen($name));    // length of filename
        $fr      .= pack('v', 0);                // extra field length
        $fr      .= $name;

        // "file data" segment
        $fr .= $zdata;

        // "data descriptor" segment (optional but necessary if archive is not
        // served as file)
        $fr .= pack('V', $crc);                 // crc32
        $fr .= pack('V', $c_len);               // compressed filesize
        $fr .= pack('V', $unc_len);             // uncompressed filesize

        // add this entry to array
        $this -> datasec[] = $fr;
        $new_offset        = strlen(implode('', $this->datasec));

        // now add to central directory record
        $cdrec = "x50x4bx01x02";
        $cdrec .= "x00x00";                // version made by
        $cdrec .= "x14x00";                // version needed to extract
        $cdrec .= "x00x00";                // gen purpose bit flag
        $cdrec .= "x08x00";                // compression method
        $cdrec .= $hexdtime;                 // last mod time & date
        $cdrec .= pack('V', $crc);           // crc32
        $cdrec .= pack('V', $c_len);         // compressed filesize
        $cdrec .= pack('V', $unc_len);       // uncompressed filesize
        $cdrec .= pack('v', strlen($name) ); // length of filename
        $cdrec .= pack('v', 0 );             // extra field length
        $cdrec .= pack('v', 0 );             // file comment length
        $cdrec .= pack('v', 0 );             // disk number start
        $cdrec .= pack('v', 0 );             // internal file attributes
        $cdrec .= pack('V', 32 );            // external file attributes - 'archive' bit set

        $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
        $this -> old_offset = $new_offset;

        $cdrec .= $name;

        // optional extra field, file comment goes here
        // save to central directory
        $this -> ctrl_dir[] = $cdrec;
    } // end of the 'addFile()' method

    /**
     * Dumps out file
     *
     * @return  string  the zipped file
     *
     * @access public
     */
    function file()
    {
        $data    = implode('', $this -> datasec);
        $ctrldir = implode('', $this -> ctrl_dir);

        return
            $data .
            $ctrldir .
            $this -> eof_ctrl_dir .
            pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries "on this disk"
            pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries overall
            pack('V', strlen($ctrldir)) .           // size of central dir
            pack('V', strlen($data)) .              // offset to start of central dir
            "x00x00";                             // .zip file comment length
    } // end of the 'file()' method

} // end of the 'PHPZip' class
?>

[!--infotagslink--]

相关文章

  • C#连接SQL数据库和查询数据功能的操作技巧

    本文给大家分享C#连接SQL数据库和查询数据功能的操作技巧,本文通过图文并茂的形式给大家介绍的非常详细,需要的朋友参考下吧...2021-05-17
  • php简单数据操作的实例

    最基础的对数据的增加删除修改操作实例,菜鸟们收了吧...2013-09-26
  • 解决Mybatis 大数据量的批量insert问题

    这篇文章主要介绍了解决Mybatis 大数据量的批量insert问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-01-09
  • Antd-vue Table组件添加Click事件,实现点击某行数据教程

    这篇文章主要介绍了Antd-vue Table组件添加Click事件,实现点击某行数据教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-17
  • 详解如何清理redis集群的所有数据

    这篇文章主要介绍了详解如何清理redis集群的所有数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-18
  • vue 获取到数据但却渲染不到页面上的解决方法

    这篇文章主要介绍了vue 获取到数据但却渲染不到页面上的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-19
  • mybatis-plus 处理大数据插入太慢的解决

    这篇文章主要介绍了mybatis-plus 处理大数据插入太慢的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-18
  • php把读取xml 文档并转换成json数据代码

    在php中解析xml文档用专门的函数domdocument来处理,把json在php中也有相关的处理函数,我们要把数据xml 数据存到一个数据再用json_encode直接换成json数据就OK了。...2016-11-25
  • Android模拟器上模拟来电和短信配置

    如果我们的项目需要做来电及短信的功能,那么我们就得在Android模拟器开发这些功能,本来就来告诉我们如何在Android模拟器上模拟来电及来短信的功能。 在Android模拟...2016-09-20
  • postgresql数据添加两个字段联合唯一的操作

    这篇文章主要介绍了postgresql数据添加两个字段联合唯一的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-04
  • 夜神android模拟器设置代理的方法

    夜神android模拟器如何设置代理呢?对于这个问题其实操作起来是非常的简单,下面小编来为各位详细介绍夜神android模拟器设置代理的方法,希望例子能够帮助到各位。 app...2016-09-20
  • JS中artdialog弹出框控件之提交表单思路详解

    artDialog是一个基于javascript编写的对话框组件,它拥有精致的界面与友好的接口。本文给大家介绍JS中artdialog弹出框控件之提交表单思路详解,对本文感兴趣的朋友一起学习吧...2016-04-19
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • C#模拟http 发送post或get请求的简单实例

    下面小编就为大家带来一篇C#模拟http 发送post或get请求的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • Vue生命周期activated之返回上一页不重新请求数据操作

    这篇文章主要介绍了Vue生命周期activated之返回上一页不重新请求数据操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-26
  • c# socket网络编程接收发送数据示例代码

    这篇文章主要介绍了c# socket网络编程,server端接收,client端发送数据,大家参考使用吧...2020-06-25
  • vue 数据(data)赋值问题的解决方案

    这篇文章主要介绍了vue 数据(data)赋值问题的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-29
  • Python3 常用数据标准化方法详解

    这篇文章主要介绍了Python3 常用数据标准化方法详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-24
  • 解决vue watch数据的方法被调用了两次的问题

    这篇文章主要介绍了解决vue watch数据的方法被调用了两次的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-07
  • angularjs $http实现form表单提交示例

    这篇文章主要介绍了angularjs $http实现form表单提交示例,非常具有实用价值,需要的朋友可以参考下 ...2017-06-15