yjiang's cake

PHPRPC模式在 php5.4版本下报错问题

Fatal error: Cannot redeclare gzdecode() /beartech/phprpc/compat.php on line 181

因为php5.4已经自带了gzdecode函数,所以导致了此冲突;使用

if(!function_exists('gzdecode')){
}

包含phprpc的函数即可.

php字母大小写转换的几个函数

  • strtolower (全部转换为小写)
  • ucfirst (第一个首字母大写)
  • ucwords (单词首字母大写)
  • strtoupper (全部转换为大写)

    例:
    
    
    i will go home
    I will go home
    I Will Go Home
    I WILL GO HOME
    

PHP伪造user-agent

1.file_get_contents伪造user_agent

$UserAgent = 'Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.2';
ini_set('user_agent', $UserAgent);

2.curl伪造user_agent

$user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5";
curl_setopt($c, CURLOPT_USERAGENT, $user_agent);

for example:

有待完善的OOP批量上传


表单:
enctype="multipart/form-data"

>
输入框:
引用此Uploads.php文件
$Upload = new uploads($_FILES['upload_pic'], '/tmp/');
$imgs = $Upload->get_file_infos();
class Uploads {
private $files;
private $save_path;
private $file_names;
private $file_sizes;
private $file_widths;
private $file_heights;
private $file_types;
private $file_infos;
public function __construct($files, $save_path){
$this->files = $files;
$this->save_path = $save_path;
$this->count = count($files['name']);
$this->unique_name = $this->get_unique_name();
$this->fileAttr2array();
$this->move_files();
}
public function uploads(){ // {{{
echo "

";
		print_r($this->files);
	}	//	}}}
	private function fileAttr2array(){	//	{{{
		$files = $this->files;
		$unique_name = $this->unique_name;
		$fileInfos = array();
		for($i=0;$i<$this->count;$i++){
			$fileInfos[$i]['name'] = $unique_name[$i];
			$fileInfos[$i]['size'] = self::get_file_attr($i, 'size');
			$fileInfos[$i]['type'] = self::get_file_attr($i, 'type');
			$fileInfos[$i]['width'] = self::get_file_attr($i, 'width');
			$fileInfos[$i]['height'] = self::get_file_attr($i, 'height');
		}
		$this->file_infos = $fileInfos;
	}	//	}}}
	private function get_file_attr($num, $attr_name){	//	{{{
		$files = $this->files;
		if($attr_name == 'width'){
			$pic_attr = (getimagesize($files['tmp_name'][$num]));
			return $pic_attr[0];
		}
		elseif($attr_name == 'height'){
			$pic_attr = (getimagesize($files['tmp_name'][$num]));
			return $pic_attr[1];
		}
		else{
			return $files[$attr_name][$num];
		}
	}	//	}}}
	private function move_files(){	//	{{{
		$files = $this->files;
		$unique_name = $this->unique_name;
		$file_infos = $this->file_infos;
		if(is_dir($this->save_path)){
			for($i=0;$i<$this->count;$i++){
				exec('mv ' . $files['tmp_name'][$i] . ' ' .$this->save_path . $unique_name[$i]);		
			}
		}
		else {
			exec('mkdir ' . $this->save_path);
			self::move_files();
		}
	}	//	}}}
	private function get_unique_name(){	// 生成对应文件数量的唯一ID作为文件名	{{{
		$files = $this->files;
		$unique_name = array();
		for($i=0;$i<$this->count;$i++){
			$type = explode('.', $files['name'][$i]);
			$unique_id = md5(time() . mt_rand(1,1000000));
			$unique_name[$i] = $unique_id.'.'.$type[1];
		}
		return $unique_name;
	}	//	}}}
	public function get_file_infos(){	//	{{{
		return $this->file_infos;
	}	//	}}}
}

==========================================
已知问题:
1.上传图片超过服务器显限制的大小时上传失败,但依旧获取到了图片name

使用phpmyadmin同步功能迁移mysql数据库

同步功能默认只有localhost,不能修改,这里需要在 config.inc.php里添加一个参数:
/* AllowArbitraryServer */
$cfg['AllowArbitraryServer'] = true;
这样就可以输入目标地址了。

Copyright © 2016 yjiang's cake

返回顶部