$file = $_FILES['file'];//得到传输的数据
var_dump($file);die;
//得到文件名称
$name = $file['name'];
$type = strtolower(substr($name,strrpos($name,'.')+1)); //得到文件类型,并且都转化成小写
$allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
//判断文件类型是否被允许上传
if(!in_array($type, $allow_type)){
//如果不被允许,则直接停止程序运行
return '失败';
}
//判断是否是通过HTTP POST上传的
if(!is_uploaded_file($file['tmp_name'])){
//如果不是通过HTTP POST上传的
return '失败' ;
}
$upload_path = $_SERVER['DOCUMENT_ROOT']."/static/images/".date('Ymd').uniqid('image_').'.jpg'; //上传文件的存放路径
//开始移动文件到相应的文件夹
// if(move_uploaded_file($file['tmp_name'],$upload_path)){
// $fp = fopen($upload_path, 'rb');
// $content = fread($fp, filesize($upload_path)); //二进制数据
// fclose($fp);
// $upload_path = $_SERVER['DOCUMENT_ROOT']."/static/images/".date('Ymd').'.jpg'; //上传文件的存放路径
//
// $fp = fopen($upload_path, 'w+');
// fwrite($fp,$content);
// fclose($fp);
// echo $content;
// }else{
// echo "Failed!";
// }

$fp = fopen($file['tmp_name'],'rb');
$data['image_content'] = fread($fp, filesize($file['tmp_name'])); //二进制数据
echo $data['image_content'];die;
$data['image_name'] = date('Ymd').uniqid('image_').'.jpg';
$data['image_type'] = 'jpg';