php判断某个值是否为数组成员

使用 in_array 这个函数,可以用来判断某个值是否为数组成员。
如果你有一个被禁的名单,如果用户属于其中之一,则踢之。你不会像我以前一样写个超长的if 判断吧吧?

if ($a=="aaaa"||$a=="bbbb"||$a=="ccc"){
echo "$user 在被禁名单中";
}

用in_array, 这样写好些:

$exclude_array = array("aaaa","bbbb","cccc");
if (in_array($user,$exclude_array)){
echo "$user 在被禁名单中";
}

class文件

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

/*--------------------------------------------------
 | TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.1
 | By Devin Doucette
 | Copyright (c) 2005 Devin Doucette
 | Email: darksnoopy@shaw.ca
 +--------------------------------------------------
 | Email bugs/suggestions to darksnoopy@shaw.ca
 +--------------------------------------------------
 | This script has been created and released under
 | the GNU GPL and is free to use and redistribute
 | only if this copyright statement is not removed
 +--------------------------------------------------*/
 
class archive
{
function archive($name)
{
   $this->options = array (
    'basedir' => ".",
    'name' => $name,
    'prepend' => "",
    'inmemory' => 0,
    'overwrite' => 0,
    'recurse' => 1,
    'storepaths' => 1,
    'followlinks' => 0,
    'level' => 3,
    'method' => 1,
    'sfx' => "",
    'type' => "",
    'comment' => ""
   );
   $this->files = array ();
   $this->exclude = array ();
   $this->storeonly = array ();
   $this->error = array ();
}
 
function set_options($options)
{
   foreach ($options as $key => $value)
    $this->options[$key] = $value;
   if (!empty ($this->options['basedir']))
   {
    $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
    $this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
    $this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
   }
   if (!empty ($this->options['name']))
   {
    $this->options['name'] = str_replace("\\", "/", $this->options['name']);
    $this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
   }
   if (!empty ($this->options['prepend']))
   {
    $this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
    $this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
    $this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
    $this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
   }
}
 
function create_archive()
{
   $this->make_list();
 
   if ($this->options['inmemory'] == 0)
   {
    $pwd = getcwd();
    chdir($this->options['basedir']);
    if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
    {
     $this->error[] = "File {$this->options['name']} already exists.";
     chdir($pwd);
     return 0;
    }
    else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
     chdir($pwd);
    else
    {
     $this->error[] = "Could not open {$this->options['name']} for writing.";
     chdir($pwd);
     return 0;
    }
   }
   else
    $this->archive = "";
 
   switch ($this->options['type'])
   {
   case "zip":
    if (!$this->create_zip())
    {
     $this->error[] = "Could not create zip file.";
     return 0;
    }
    break;
   case "bzip":
    if (!$this->create_tar())
    {
     $this->error[] = "Could not create tar file.";
     return 0;
    }
    if (!$this->create_bzip())
    {
     $this->error[] = "Could not create bzip2 file.";
     return 0;
    }
    break;
   case "gzip":
    if (!$this->create_tar())
    {
     $this->error[] = "Could not create tar file.";
     return 0;
    }
    if (!$this->create_gzip())
    {
     $this->error[] = "Could not create gzip file.";
     return 0;
    }
    break;
   case "tar":
    if (!$this->create_tar())
    {
     $this->error[] = "Could not create tar file.";
     return 0;
    }
   }
 
   if ($this->options['inmemory'] == 0)
   {
    fclose($this->archive);
    if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
     unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
   }
}
 
function add_data($data)
{
   if ($this->options['inmemory'] == 0)
    fwrite($this->archive, $data);
   else
    $this->archive .= $data;
}
 
function make_list()
{
   if (!empty ($this->exclude))
    foreach ($this->files as $key => $value)
     foreach ($this->exclude as $current)
      if ($value['name'] == $current['name'])
       unset ($this->files[$key]);
   if (!empty ($this->storeonly))
    foreach ($this->files as $key => $value)
     foreach ($this->storeonly as $current)
      if ($value['name'] == $current['name'])
       $this->files[$key]['method'] = 0;
   unset ($this->exclude, $this->storeonly);
}
 
function add_files($list)
{
   $temp = $this->list_files($list);
   foreach ($temp as $current)
    $this->files[] = $current;
}
 
function exclude_files($list)
{
   $temp = $this->list_files($list);
   foreach ($temp as $current)
    $this->exclude[] = $current;
}
 
function store_files($list)
{
   $temp = $this->list_files($list);
   foreach ($temp as $current)
    $this->storeonly[] = $current;
}
 
function list_files($list)
{
   if (!is_array ($list))
   {
    $temp = $list;
    $list = array ($temp);
    unset ($temp);
   }
 
   $files = array ();
 
   $pwd = getcwd();
   chdir($this->options['basedir']);
   foreach ($list as $current)
   {
    $current = str_replace("\\", "/", $current);
    $current = preg_replace("/\/+/", "/", $current);
    $current = preg_replace("/\/$/", "", $current);
    if (strstr($current, "*"))
    {
     $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
     $regex = str_replace("*", ".*", $regex);
     $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
     $temp = $this->parse_dir($dir);
     foreach ($temp as $current2)
      if (preg_match("/^{$regex}$/i", $current2['name']))
       $files[] = $current2;
     unset ($regex, $dir, $temp, $current);
    }
    else if (@is_dir($current))
    {
     echo "dir";
     $temp = $this->parse_dir($current);
     foreach ($temp as $file)
      $files[] = $file;
     unset ($temp, $file);
    }
    else if (@file_exists($current))
     $files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
      preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
      substr($current, strrpos($current, "/") + 1) : $current),
      'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
      'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
    else {
       echo "other error ";
    }
   }  
 
   chdir($pwd);
 
   unset ($current, $pwd);
 
   usort($files, array ("archive", "sort_files"));
   //prt($files); //die;
   return $files;
 
}
 
function parse_dir($dirname)
{
   if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))
    $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
     preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
     substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
   else
    $files = array ();
   $dir = @opendir($dirname);
 
   while ($file = @readdir($dir))
   {
    $fullname = $dirname . "/" . $file;
    if ($file == "." || $file == "..")
     continue;
    else if (@is_dir($fullname))
    {
     if (empty ($this->options['recurse']))
      continue;
     $temp = $this->parse_dir($fullname);
     foreach ($temp as $file2)
      $files[] = $file2;
    }
    else if (@file_exists($fullname))
     $files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .
      preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
      substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
      'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
      'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
   }
 
   @closedir($dir);
 
   return $files;
}
 
function sort_files($a, $b)
{
   if ($a['type'] != $b['type'])
    if ($a['type'] == 5 || $b['type'] == 2)
     return -1;
    else if ($a['type'] == 2 || $b['type'] == 5)
     return 1;
   else if ($a['type'] == 5)
    return strcmp(strtolower($a['name']), strtolower($b['name']));
   else if ($a['ext'] != $b['ext'])
    return strcmp($a['ext'], $b['ext']);
   else if ($a['stat'][7] != $b['stat'][7])
    return $a['stat'][7] > $b['stat'][7] ? -1 : 1;
   else
    return strcmp(strtolower($a['name']), strtolower($b['name']));
   return 0;
}
 
function download_file()
{
   if ($this->options['inmemory'] == 0)
   {
    $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
    return;
   }
   switch ($this->options['type'])
   {
   case "zip":
    header("Content-Type: application/zip");
    break;
   case "bzip":
    header("Content-Type: application/x-bzip2");
    break;
   case "gzip":
    header("Content-Type: application/x-gzip");
    break;
   case "tar":
    header("Content-Type: application/x-tar");
   }
   $header = "Content-Disposition: attachment; filename=\"";
   $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
   $header .= "\"";
   header($header);
   header("Content-Length: " . strlen($this->archive));
   header("Content-Transfer-Encoding: binary");
   header("Cache-Control: no-cache, must-revalidate, max-age=60");
   header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
   print($this->archive);
}
}
 
class tar_file extends archive
{
function tar_file($name)
{
   $this->archive($name);
   $this->options['type'] = "tar";
}
 
function create_tar()
{
   $pwd = getcwd();
   chdir($this->options['basedir']);
 
   foreach ($this->files as $current)
   {
    if ($current['name'] == $this->options['name'])
     continue;
    if (strlen($current['name2']) > 99)
    {
     $path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
     $current['name2'] = substr($current['name2'], strlen($path));
     if (strlen($path) > 154 || strlen($current['name2']) > 99)
     {
      $this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
      continue;
     }
    }
    $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o", 
     $current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]), 
     sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]), 
     "        ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ", 
     "Unknown", "Unknown", "", "", !empty ($path) ? $path : "", "");
 
    $checksum = 0;
    for ($i = 0; $i < 512; $i++)
     $checksum += ord(substr($block, $i, 1));
    $checksum = pack("a8", sprintf("%07o", $checksum));
    $block = substr_replace($block, $checksum, 148, 8);
 
    if ($current['type'] == 2 || $current['stat'][7] == 0)
     $this->add_data($block);
    else if ($fp = @fopen($current['name'], "rb"))
    {
     $this->add_data($block);
     while ($temp = fread($fp, 1048576))
      $this->add_data($temp);
     if ($current['stat'][7] % 512 > 0)
     {
      $temp = "";
      for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
       $temp .= "\0";
      $this->add_data($temp);
     }
     fclose($fp);
    }
    else
     $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
   }
 
   $this->add_data(pack("a1024", ""));
 
   chdir($pwd);
 
   return 1;
}
 
function extract_files()
{
   $pwd = getcwd();
   chdir($this->options['basedir']);
 
   if ($fp = $this->open_archive())
   {
    if ($this->options['inmemory'] == 1)
     $this->files = array ();
 
    while ($block = fread($fp, 512))
    {
     $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
     $file = array (
      'name' => $temp['prefix'] . $temp['name'],
      'stat' => array (
       2 => $temp['mode'],
       4 => octdec($temp['uid']),
       5 => octdec($temp['gid']),
       7 => octdec($temp['size']),
       9 => octdec($temp['mtime']),
      ),
      'checksum' => octdec($temp['checksum']),
      'type' => $temp['type'],
      'magic' => $temp['magic'],
     );
     if ($file['checksum'] == 0x00000000)
      break;
     else if (substr($file['magic'], 0, 5) != "ustar")
     {
      $this->error[] = "This script does not support extracting this type of tar file.";
      break;
     }
     $block = substr_replace($block, "        ", 148, 8);
     $checksum = 0;
     for ($i = 0; $i < 512; $i++)
      $checksum += ord(substr($block, $i, 1));
     if ($file['checksum'] != $checksum)
      $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
 
     if ($this->options['inmemory'] == 1)
     {
      $file['data'] = fread($fp, $file['stat'][7]);
      fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
      unset ($file['checksum'], $file['magic']);
      $this->files[] = $file;
     }
     else if ($file['type'] == 5)
     {
      if (!is_dir($file['name']))
       mkdir($file['name'], $file['stat'][2]);
     }
     else if ($this->options['overwrite'] == 0 && file_exists($file['name']))
     {
      $this->error[] = "{$file['name']} already exists.";
      continue;
     }
     else if ($file['type'] == 2)
     {
      symlink($temp['symlink'], $file['name']);
      chmod($file['name'], $file['stat'][2]);
     }
     else if ($new = @fopen($file['name'], "wb"))
     {
      fwrite($new, fread($fp, $file['stat'][7]));
      fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
      fclose($new);
      chmod($file['name'], $file['stat'][2]);
     }
     else
     {
      $this->error[] = "Could not open {$file['name']} for writing.";
      continue;
     }
     chown($file['name'], $file['stat'][4]);
     chgrp($file['name'], $file['stat'][5]);
     touch($file['name'], $file['stat'][9]);
     unset ($file);
    }
   }
   else
    $this->error[] = "Could not open file {$this->options['name']}";
 
   chdir($pwd);
}
 
function open_archive()
{
   return @fopen($this->options['name'], "rb");
}
}
 
class gzip_file extends tar_file
{
function gzip_file($name)
{
   $this->tar_file($name);
   $this->options['type'] = "gzip";
}
 
function create_gzip()
{
   if ($this->options['inmemory'] == 0)
   {
    $pwd = getcwd();
    chdir($this->options['basedir']);
    if ($fp = gzopen($this->options['name'], "wb{$this->options['level']}"))
    {
     fseek($this->archive, 0);
     while ($temp = fread($this->archive, 1048576))
      gzwrite($fp, $temp);
     gzclose($fp);
     chdir($pwd);
    }
    else
    {
     $this->error[] = "Could not open {$this->options['name']} for writing.";
     chdir($pwd);
     return 0;
    }
   }
   else
    $this->archive = gzencode($this->archive, $this->options['level']);
 
   return 1;
}
 
function open_archive()
{
   return @gzopen($this->options['name'], "rb");
}
}
 
class bzip_file extends tar_file
{
function bzip_file($name)
{
   $this->tar_file($name);
   $this->options['type'] = "bzip";
}
 
function create_bzip()
{
   if ($this->options['inmemory'] == 0)
   {
    $pwd = getcwd();
    chdir($this->options['basedir']);
    if ($fp = bzopen($this->options['name'], "wb"))
    {
     fseek($this->archive, 0);
     while ($temp = fread($this->archive, 1048576))
      bzwrite($fp, $temp);
     bzclose($fp);
     chdir($pwd);
    }
    else
    {
     $this->error[] = "Could not open {$this->options['name']} for writing.";
     chdir($pwd);
     return 0;
    }
   }
   else
    $this->archive = bzcompress($this->archive, $this->options['level']);
 
   return 1;
}
 
function open_archive()
{
   return @bzopen($this->options['name'], "rb");
}
}
 
class zip_file extends archive
{
function zip_file($name)
{
   $this->archive($name);
   $this->options['type'] = "zip";
}
 
function create_zip()
{
   $files = 0;
   $offset = 0;
   $central = "";
 
   if (!empty ($this->options['sfx']))
    if ($fp = @fopen($this->options['sfx'], "rb"))
    {
     $temp = fread($fp, filesize($this->options['sfx']));
     fclose($fp);
     $this->add_data($temp);
     $offset += strlen($temp);
     unset ($temp);
    }
    else
     $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
 
   $pwd = getcwd();
   chdir($this->options['basedir']);
 
   foreach ($this->files as $current)
   {
    if ($current['name'] == $this->options['name'])
     continue;
 
    $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
    $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
     ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
 
    $block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
 
    if ($current['stat'][7] == 0 && $current['type'] == 5)
    {
     $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
     $block .= $current['name2'] . "/";
     $this->add_data($block);
     $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
      0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
     $central .= $current['name2'] . "/";
     $files++;
     $offset += (31 + strlen($current['name2']));
    }
    else if ($current['stat'][7] == 0)
    {
     $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
     $block .= $current['name2'];
     $this->add_data($block);
     $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
      0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
     $central .= $current['name2'];
     $files++;
     $offset += (30 + strlen($current['name2']));
    }
    else if ($fp = @fopen($current['name'], "rb"))
    {
     $temp = fread($fp, $current['stat'][7]);
     fclose($fp);
     $crc32 = crc32($temp);
     if (!isset($current['method']) && $this->options['method'] == 1)
     {
      $temp = gzcompress($temp, $this->options['level']);
      $size = strlen($temp) - 6;
      $temp = substr($temp, 2, $size);
     }
     else
      $size = strlen($temp);
     $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
     $block .= $current['name2'];
     $this->add_data($block);
     $this->add_data($temp);
     unset ($temp);
     $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
      (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
      $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
     $central .= $current['name2'];
     $files++;
     $offset += (30 + strlen($current['name2']) + $size);
    }
    else
     $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
   }
 
   $this->add_data($central);
 
   $this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
    !empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
 
   if (!empty ($this->options['comment']))
    $this->add_data($this->options['comment']);
 
   chdir($pwd);
 
   return 1;
}
}

————

例子

———-

//TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES Examples
 
//Examples of Compression:
 
//The following example creates a gzipped tar file:
// Assume the following script is executing in /var/www/htdocs/test
// Create a new gzip file test.tgz in htdocs/test
$test = new gzip_file("htdocs/test/test.tgz");
// Set basedir to "../..", which translates to /var/www
// Overwrite /var/www/htdocs/test/test.tgz if it already exists
// Set compression level to 1 (lowest)
//$test->set_options(array('basedir' => "../..", 'overwrite' => 1, 'level' => 1));
$test->set_options(
array(
'basedir' => dirname($modpath),
'inmemory' => 0, //不在内存压缩.而是直接存放到磁盘.如果要压缩下载,则可以选择为1
'recurse' => 1, //是否压缩子目录,resurse,递归的意思?
'storepaths' => 1, //是否存储目录结构,我选是。
'overwrite' => 1, //是否覆盖
'level' => 5 ,//压缩比
'name' => $zipFileName, //压缩最后生成的文件名,无需再次设置。这里是为了解说方便才放上来的。
'prepend' => "", //未知
'followlinks' => 0, //未知
'method' => 1, //未知
'sfx' => "", //不知道什么意思
'type' => "zip", //是zip还是tar...,无需设置,这里为了方便解说。放上来。
'comment' => ""
)
);
// Add entire htdocs directory and all subdirectories
// Add all php files in htsdocs and its subdirectories
$test->add_files(array("htdocs", "htsdocs/*.php"));
// Exclude all jpg files in htdocs and its subdirectories
$test->exclude_files("htdocs/*.jpg");
// Create /var/www/htdocs/test/test.tgz
$test->create_archive();
// Check for errors (you can check for errors at any point)
if (count($test->errors) > 0)
print ("Errors occurred."); // Process errors here
 
//The following example creates a zip file:
// Create new zip file in the directory below the current one
$test = new zip_file("../example.zip");
// All files added will be relative to the directory in which the script is 
//    executing since no basedir is set.
// Create archive in memory
// Do not recurse through subdirectories
// Do not store file paths in archive
$test->set_options(array('inmemory' => 1, 'recurse' => 0, 'storepaths' => 0));
// Add lib/archive.php to archive
$test->add_files("src/archive.php");
// Add all jpegs and gifs in the images directory to archive
$test->add_files(array("images/*.jp*g", "images/*.gif"));
// Store all exe files in bin without compression
$test->store_files("bin/*.exe");
// Create archive in memory
$test->create_archive();
// Send archive to user for download
$test->download_file();
 
//Examples of Decompression:
 
//The following example extracts a bzipped tar file:
// Open test.tbz2
$test = new bzip_file("test.tbz2");
// Overwrite existing files
$test->set_options(array('overwrite' => 1));
// Extract contents of archive to disk
$test->extract_files();
 
//The following example extracts a tar file:
// Open archives/test.tar
$test = new tar_file("archives/test.tar");
// Extract in memory
$test->set_options(array('inmemory' => 0));
// Extract archive to memory
$test->extract_files();
// Write out the name and size of each file extracted
foreach ($test->files as $file)
print ("File " + $file['name'] + " is " + $file['stat'][7] + " bytes\n");

mysql 错误处理

网上的例子经常使用die()来处理mysql错误:即显示错误内容并中止程序。其实这样做是有一定危险的,尤其是代码中有敏感内容的时候,如密码,api 吗等。如果mysql出错,用户就有可能获得这些敏感内容。

而且作为一个用于生产的成品,这样相当地用户不友好。可以用mysql_errno(),对不同错误进行处理:

$error_message = mysql_error();

mysql_query("INSERT INTO the_itemsordered (
orderref,
product,
quantity,
test,
date)
VALUES(
'".$OrderReference."',
'".$OrderProductNames."',
'".$Quantity."',
'".$OrderIsTest."',
CURRENT_TIMESTAMP )");
$error_no = mysql_errno();
$error_message = mysql_error();
if ($error_no>0){ //出错
//bla bla
}

喜欢BudgetVM处理宕机的方式

其实我说我不喜欢折腾,那是在撒谎。年纪一大把了,有时候还会没日没夜地瞎折腾。前段时间虚拟主机出现问题,情急之中,买了budgtvm的 vps,玩起了linux,重装了两三次系统,乐此不疲。

budgetvm的机器一直很稳定,几个星期来,用monitor.us监控,图上的线像死人的心电图一样平稳。不过昨天开始出现访问速度慢,ping掉包的问题。有意思的是,budgetvm的vps稳定的时候,我天天琢磨着换个服务商。这次出了问题,看到了他们处理的问题的方式,我反而决定不换了。

出了问题后我提交了小票,今天早上收到回答,当然不算是很快。但回信的Nick友好而诚恳,先解释了原因,然后保证说他们正在十分努力地解决问题,几个小时后就会彻底解决问题,而且还给了我半个月的补偿!

vps也好,主机也好,还是国外的靠谱些,他们没有QQ客服,也没有群,一般也不会有24小时的实时帮助,不用中文,国人用起来觉得不习惯。但是,以下几个关键国内vps提供商是没法比的。

1. 说不超卖,就不超卖(看各人如何定义超卖了)。一个服务器到达了一定承载力,宁愿暂时歇业,也不再放新客户。一般情况下别期望国人有如此强的原则性。

2. 论技术能力,总得来讲,还是老美有经验和实力。

3. 属于自己的硬件。

4. 出现宕机等问题承诺有补偿,就会补偿。

无论国内还是国外,指望一出问题就立即得到回应和解决都是不现实的。当然国内人力便宜,一般会有在线QQ听你抱怨一下,给你点心理安慰。国外很少会有能得到实时回应的情况,都要先提交小票的。

 

几个靠谱的vps提供商

研究了几天,感觉比较靠谱的vps供应商有:

1. http://budgetvm.com/

公司形象有点土气,不够酷,还搞了个老土的our mission什么的。我用的就是他们洛杉矶的服务器

价格便宜;服务反应速度中等;稳定性优秀,用monitor.us观察了很长时间,图表像死人的心电图一样,不带跳的;la的硬件不好,探针测试各项指标倒数第一。不过,稳定就好,我很满意。

2. http://ramhost.us/

口碑好,连续多次在lowendbox.com最佳vps评选中获得第一。从网上的记录来看,网站站长不够友好,急了会骂人,一些他觉得的滥用的客户,可能直接给你删除没商量。这个服务商的独特之处是公布各个服务器的各项监控记录,同时公布pingdom.com对其各服务器的监控记录,你可以看到服务器的真实情况,确定服务器没有超卖,还可以看到他们的服务器历史在线率。买他的服务器,即使是最便宜的15美元一年的vps (tinyvz.com),心里也踏实。

3. http://www.evorack.com

国外评价也比较高。可惜只有伦敦机房,国内访问速度一般。特点是服务特别专业到位,网站文字及客服都让你觉得自己像个贵客,恨不能一口一个亲字。跟ramhost.us及homezz.com的东哥形成鲜明对比。

4. http://www.leaseweb.com

这可是个建于上个世纪90年代初的老古董级公司。价格也合理,leaseweb提供低价独服(35欧元一个月)。网上的口碑不错,不过骂的人也不在少数。wikipedia的服务器就在它那。我需要独服的话就找它。机房在荷兰阿姆斯特丹,国内访问速度一般。

再加两个

5. http://prgmr.com ,网标题都是用文本符号堆成的,副标题是:“我们不假设你是小白。”

创始时间:2005

虚拟技术:Xen

操作系统:Linux

入门套餐:$5/月 64M RAM+512M swap, 1.5GB 空间,10G流量

服务器位置:未知

据说店主是个出过多本书的技术高人,感觉值得托付。

6. https://hostigation.com/

首页就一句话:欢迎,我们以疯颠颠的价格提供疯颠颠的套餐,疯了!

创始时间:2006,lowendbox优秀vps前几名。

虚拟技术:KVM, OpenVZ, 独立主机

操作系统:Linux

入门套餐:KVM $30/年,128M RAM, 10G空间,500G流量
OpenVZ $20/年,128/256M RAM, 10G空间,500GB流量

服务器位置:Charlotte(北卡,美国东南),LA(美国西海岸)

欢迎添加。