等待几秒钟,让下载完成,然后执行PHP代码


Wait for few seconds to let download finish and then execute PHP code

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

现在我面临的问题是,PHP中的rename()函数在我执行下载图像函数(使用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文件中。

为什么不直接使用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;