I am working with Google Chart API where I am converting the graph into image and then download it into my downloads folder. Now after download I want to rename the image file and move it to other directory for which I am using rename()
function in PHP.
Now the problem I am facing is that the rename()
function in PHP executes before I can execute the download image function (which is in javascript) and hence it gives me error showing "Specified file not found".
I have tried using PHP delay function usleep()
and javascript function setTimeOut()
and I also tried "time-wasting" loops. but didn't have any success.
Can Someone please suggest me something I can implement to accomplish this.
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');
?>
This is grchartimg library which convert and download the graph image. I want the overwrite protection that is why I am using rename. Because after renaming I want to embed this image in PDF file.