0

我正在使用 Google Chart API 将图表转换为图像,然后将其下载到我的下载文件夹中。现在下载后我想重命名图像文件并将其移动到我rename()在 PHP 中使用函数的其他目录。

现在我面临的问题是rename()PHP 中的函数在我可以执行下载图像函数(在 javascript 中)之前执行,因此它给了我错误显示“找不到指定的文件”。

我尝试过使用 PHP 延迟函数usleep()和 javascript 函数setTimeOut(),也尝试过“浪费时间”的循环。但没有任何成功。有人可以建议我一些我可以实现的东西。

This is my code:

/*Firstly there is the google line chart code */
In body I have:
<script type="text/javascript">
onload = function download_this(){
    grChartImg.DownloadImage('chart_div');
}
</script>

//PHP
<?
$changefrom = "C:/somelocation/Downloads/download" ;
     $changeto = __DIR__.'\mygraph';
     rename($changefrom, $changeto.'.png');
?>

这是 grchartimg 库,用于转换和下载图形图像。我想要覆盖保护,这就是我使用重命名的原因。因为重命名后我想将此图像嵌入到 PDF 文件中。

4

1 回答 1

0

为什么不直接使用 PHP 下载图像?

使用 php 从给定的谷歌图表 api url 下载图像文件

header('Content-Type: image/png');
header('Content-Disposition: attachment; filename="chart.png"');
$image = file_get_contents('http://chart.apis.google.com/chart?    chs=300x300&cht=qr&chld=L|0&chl=http%253A%252F%252Fnetcane.com%252Fprojects%252Fyourl%252F3');
header('Content-Length: ' . strlen($image));
echo $image;
于 2013-08-20T11:57:16.660 回答