2013-08-20 63 views
0

我正在使用Google Chart API,将图形转换为图像,然后将其下载到我的下载文件夹中。现在下载后我想重命名图像文件并将其移动到其他目录,我在PHP中使用rename()函数。等待几秒钟,让下载完成,然后执行PHP代码

现在我面临的问题是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文件中。

+1

你能告诉我们你的代码吗? –

+0

为什么你甚至不得不重新命名图像?你想要某种“只下载一次”的保护吗?如果是这样,你应该在代码中而不是重命名文件。 – Mario

+0

您可以尝试某种长轮询来检查脚本的状态,然后在完成时执行下载。 –

回答

0

为什么不只是使用PHP下载图像?

download image file from given google chart api url using php

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; 
+0

我通过使用内联php的谷歌图表API中的数据库提供数据。此代码适用于下载图形的图像,但我无法提供从数据库中提取的数据。 –

相关问题