2013-08-20 62 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中的數據庫提供數據。此代碼適用於下載圖形的圖像,但我無法提供從數據庫中提取的數據。 –

相關問題