<?php
function rndStr(){
$string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$len = rand(0,3)+5;
$rst = '';
$strl = strlen($string);
for($i=0;$i<$len;$i++){
$ind = rand(0, $strl);
$s = $string[$ind];
$rst .= $s;
}
return $rst;
}
$name = time() . rndStr();
$type = $_POST['datatype'];
if($type == 'img'){
$img = str_replace(' ', '+', $_POST['dataimg']);
$img = base64_decode($img);
$f = fopen('upfile/' . $name . '.jpg', 'w+');
fwrite($f, $img);
fclose($f);
echo 'upfile/' . $name . '.jpg';
}else if($type == 'qrcode'){
$pic = $_POST['dataimg'];
//$arr = getimagesize($pic);
//$pic = "data:{$arr['mime']};base64," . base64_encode(file_get_contents($pic));
$pic = "data:image/jpg;base64," . base64_encode(file_get_contents($pic));
echo $pic;
}
?>
评论3
最新资源