나는 PHP로 페이스 북 앨범을 다운로드하는 스크립트를 만들었습니다. 다운로드 버튼을 클릭하면 스크립트가 장면 뒤의 앨범에있는 모든 사진을 가져 와서 폴더 안에 압축합니다. 다운로드 프로세스가 시간이 걸릴 수 있으므로 사용자가 다운로드 버튼을 클릭하는 즉시 "진행률 표시 줄"을 시작하고 싶습니다.페이지로드시 progessbar 표시
다음은 모든 압축 파일을 생성 여기가 download.php
에 앨범 ID를 전달하고 다음하고 index.php
if ($album['count'] != "0 photos")
{
echo "<a href=\"download.php?id={$album['id']}\" title='Download this Album' class='downloadbtn'><img src=\"common/images/download_button (1).png\"></a>";
}
나는 다운로드 폴더에 이미지를 다운로드하고 download.php
의 코드가있다 해당 이미지 및 해당 zip 파일을 다운로드하십시오.
<?php
require 'facebook/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxx',
'cookie' => true,
));
//GETTING THE ID HERE FROM INDEX.PHP FILE
$albumid = $_GET['id'];
$photos = $facebook->api("/{$albumid}/photos?limit=50");
$file_name = rand(1, 99999) . "_image.zip";
$albumArr = array();
foreach ($photos['data'] as $photo) {
$albumArr[] = $photo['source'];
}
create_zip($albumArr, $file_name);
function create_zip($files, $file_name, $overwrite = false) {
$i = 0;
$imgFiles = array();
foreach ($files as $imglink) {
$img = @file_get_contents($imglink);
$destination_path = 'downloads/' . time() . "Image_" . $i . '.jpg';
@file_put_contents($destination_path, $img);
$imgFiles[] = $destination_path;
$i++;
}
if (file_exists($file_name) && !$overwrite) {
return false;
}
$valid_files = array();
if (is_array($imgFiles)) {
foreach ($imgFiles as $file) {
$valid_files[] = $file;
}
}
if (count($valid_files)) {
$zip = new ZipArchive();
if ($zip->open($file_name, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
echo "Sorry ZIP creation failed at this time";
}
$size1 = 0;
foreach ($valid_files as $file) {
$size1+= filesize($file);
$zip->addFile($file, pathinfo($file, PATHINFO_BASENAME));
}
$zip->close();
$allimages = glob('downloads/*.jpg');
foreach ($allimages as $img) { // iterate images
if (is_file($img)) {
unlink($img); // delete images
}
}
$count = $zip->numFiles;
$resultArr = array();
$resultArr['count'] = $count;
$resultArr['destination'] = $file_name;
$filename = $file_name;
$filepath = $_SERVER['HTTP_HOST'] . '/';
$path = $filepath . $filename;
if (file_exists($filename)) {
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="' . $filename . '"');
readfile($filename);
unlink($filename);
}
} else {
return false;
}
}
?>
나는 시간이 걸릴 수 있습니다 다운로드 프로세스로 "진행률 표시 줄"가능한 한 빨리 사용자가 클릭 다운로드 버튼을 시작합니다.
어떻게하면됩니까? 감사합니다
그래서 JQuery에서 비동기식 AJAX 호출을 수행하여 데이터를 가져오고로드 만 표시하면 애니메이션을 보면서 PHP가이 데이터를 가져와 AJAX로 다시 전달합니다. AJAX success() 함수가 시작되면 로딩 애니메이션을 제거하고 모든 데이터를 표시합니다. – Jimbo
진행률 표시 줄의 경우 트위터의 부트 스트랩 진행률 표시 줄 (http://twitter.github.com/bootstrap/components.html#progress)을 사용하여이 너비 %를 AJAX 호출에서 가져온 번호로 설정할 수 있습니다 PHP로. PHP에서 백분율을 알아 내고 AJAX에 대해 백분율로 반복해서 출력해야합니다. – Jimbo