phpqrcode-将文件保存到临时目录

phpqrcode-将文件保存到临时目录,php,zend-framework,qr-code,temporary,temp,Php,Zend Framework,Qr Code,Temporary,Temp,我正在尝试使用php库创建二维码。 我想将文件保存在临时文件中,以便以后使用。差不多 我正在使用Zend框架,希望使用临时目录。这就是我到目前为止所做的: require_once 'phpqrcode/qrlib.php'; require_once 'phpqrcode/qrconfig.php'; $tempDir = '/temp'; $fileName = 'test'.'.png'; $pngAbsoluteFilePath = $tempDir . $fileName; $u

我正在尝试使用php库创建二维码。

我想将文件保存在临时文件中,以便以后使用。差不多

我正在使用Zend框架,希望使用临时目录。这就是我到目前为止所做的:

require_once 'phpqrcode/qrlib.php';
require_once 'phpqrcode/qrconfig.php';

$tempDir = '/temp';

$fileName = 'test'.'.png';

$pngAbsoluteFilePath = $tempDir . $fileName;
$urlRelativeFilePath = '/temp' . $fileName;

// generating
if (!file_exists($pngAbsoluteFilePath)) {
    QRcode::png('http://mylink.com/s/'.$quiz_url, $pngAbsoluteFilePath, 'L', 4, 2);
    echo 'File generated!';
    echo '<hr />';
} else {
    echo 'File already generated! We can use this cached file to speed up site on common codes!';
    echo '<hr />';
}

echo 'Server PNG File: '.$pngAbsoluteFilePath;
echo '<hr />';

// displaying
echo '<img src="'.$urlRelativeFilePath.'" />';
第二次编辑:

当我检查我的硬盘时,我看到他只是在我的根地图上保存图像,比如'tentest.png'。。。我如何确保他将此保存在我的服务器上的临时文件夹中?

您的浏览器找不到该图像,因为它是在URL“”中查找的,该URL与您磁盘上的位置“/Applications/MAMP/htdocs/surveyanyplace/site/public/tentest.png”相关,而不是保存该文件的位置(如您所注意的“/tentestest.png”)

为了通过web服务器(Apache)直接提供文件,您必须确保图像文件位于其
DocumentRoot
(通常是Zend Framework应用程序的“公共”文件夹)下

一种方法是创建以下目录:“/Applications/MAMP/htdocs/surveyanyplace/site/public/qrocodecaches”,并将
$pngabSolutionFilePath
$urlRelativeFilePath
更改如下:

$pngAbsoluteFilePath = APPLICATION_PATH . '/../public/qrcodecaches/' . $fileName;
$urlRelativeFilePath = '/qrcodecaches/' . $fileName;
$tempDir
可以删除)


注意:在处理子目录中的应用程序时,您可能想让
$urlRelativeFilePath
更具可移植性

也许您需要将
$tempDir
更改为
/temp/
(带尾随斜杠)?然后我得到一个类似于tis的警告:warning:imagepng(/temp/test.png):无法打开流:第43行的/Applications/MAMP/htdocs/surveyanyplace/site/library/phpqrcode/qrimage.php中没有此类文件或目录
$pngAbsoluteFilePath = APPLICATION_PATH . '/../public/qrcodecaches/' . $fileName;
$urlRelativeFilePath = '/qrcodecaches/' . $fileName;