public function getImgUrl(Request $request)
{
$file_name = $request->input('title');
if (empty($file_name )) {
self::ShowError(ErrorDefine::S_SYSTEM_ERROR,'缺少标题');
return;
}
$url = $request->input('url');
if (empty($url)) {
self::ShowError(ErrorDefine::S_SYSTEM_ERROR,'缺少url');
return;
}
$url = urldecode($url);
$file_name = $file_name . ".png";
//$PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'qr_code_temp'.DIRECTORY_SEPARATOR;
$PNG_TEMP_DIR = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'qr_code_img'.DIRECTORY_SEPARATOR;
//html PNG location prefix
$PNG_WEB_DIR = 'qr_code_img/';
include_once ('../app/Http/SDK/phpqrcode/qrlib.php');
//ofcourse we need rights to create temp dir
if (!file_exists($PNG_TEMP_DIR))
mkdir($PNG_TEMP_DIR);
$filename = $PNG_TEMP_DIR.$file_name;
$replace = $request->input("replace");
if (file_exists($PNG_TEMP_DIR .$file_name) && empty($replace)) {
$url ="http://".$_SERVER['HTTP_HOST'] ."\". $PNG_WEB_DIR.basename($filename);
$url = str_replace("\", "/", $url);
$result = array('url'=>$url);
self::ShowMessage($result,0,'请求成功');
}
//processing form input
//remember to sanitize user input in real-life solution !!!
$errorCorrectionLevel = 'L';
if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
$errorCorrectionLevel = $_REQUEST['level'];
$matrixPointSize = 4;
if (isset($_REQUEST['size']))
$matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10);
if (isset($_REQUEST['data'])) {
//it's very important!
if (trim($_REQUEST['data']) == '')
die('data cannot be empty! <a href="?">back</a>');
// user data
$filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png';
QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2);
} else {
//default data
//echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>';
QRcode::png($url, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
}
//display generated file
$url ="http://".$_SERVER['HTTP_HOST'] ."\". $PNG_WEB_DIR.basename($filename);
$url = str_replace("\", "/", $url);
//display generated file
$result = array('url'=>$url);
self::ShowMessage($result,0,'请求成功');
}