備忘技術分享

APC無法正常在DH工作,我又換了uploadprogress

繼上一篇安裝了APC後,發現APC 的upload trac無法正常使用!

總是在上傳完後才回傳status!

根據官方的資料,似乎是無法做用在fastCgi的模式下!

於是我又把站台切換成普通的CGI模式!

但依然無法達到我要的效果!

於是嚐試另一個uploadprogress的組件!

其中也是花費許多時間在調整組態!

原來uploadprogress依然不能正常作用在fastcgi模式下

且DH中所提供的

才能正常運作!

(到這裡其實我又回去試APC…但依然無解)

不過反正uploadprogress可以用了,那我也就先用它囉!

以下是它在DH安裝的方式

[code lang=”shell”]

export PATH=/usr/local/php53/bin:$PATH

wget http://pecl.php.net/get/uploadprogress -O uploadprogres.tgz &

tar -zxvf uploadprogress.tgz &

cd uploadprogress
phpize &

./configure –with-php-config=/usr/local/php53/bin/php-config &
make &
[/code]

安裝好後
可以用以下三個檔來測試一下
upload.php
[code lang=”php”]
<?php
if ($_FILES[‘file’][‘error’] === UPLOAD_ERR_OK) {
$path = ‘/tmp/upload/’ . $_FILES[‘file’][‘name’];
move_uploaded_file($_FILES[‘file’][‘tmp_name’], $path);
}
[/php]

getprogress.php
[code lang="php"]
<?php

if (isset($_GET[‘uid’])) {

// Fetch the upload progress data
$status = uploadprogress_get_info($_GET[‘uid’]);

if ($status) {

// Calculate the current percentage
echo round($status[‘bytes_uploaded’]/$status[‘bytes_total’]*100);

}
else {

// If there is no data, assume it’s done
echo 100;

}
}

[/code]

index.php

[code lang=”php”]
<?php
// Generate random string for our upload identifier
$uid = md5(uniqid(mt_rand()));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Upload Something</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/start/jquery-ui.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
<style>
#progress-bar, #upload-frame {
display: none;
}
</style>
<script>
(function ($) {
var pbar;
var started = false;
$(function () {
$(‘#upload-form’).submit(function() {
$(‘#upload-form’).hide();
pbar = $(‘#progress-bar’);
pbar.show().progressbar();
$(‘#upload-frame’).load(function () {
started = true;
alert(‘Upload Complete!’);
});
setTimeout(function () {
updateProgress($(‘#uid’).val());
}, 1000);

});

});

function updateProgress(id) {
var time = new Date().getTime();
$.get(‘getprogress.php’, { uid: id, t: time }, function (data) {
var progress = parseInt(data, 10);

if (progress < 100 || !started) {
started = progress < 100;
updateProgress(id);
}
started && pbar.progressbar(‘value’, progress);
});

}

}(jQuery));
</script>
</head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data" id="upload-form" target="upload-frame">
<input type="hidden" id="uid" name="UPLOAD_IDENTIFIER" value="<?php echo $uid; ?>">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload!">
</form>
<div id="progress-bar"></div>
<iframe id="upload-frame" name="upload-frame"></iframe>
</body>
</html>
[/code]
參考出處http://diggit.drupalextras.com/dreamhost-installing-drupal-drush-upload-progress-and-custom-phpini-file-all-one-shot

English ver:

Following on an installation of APC ,The APC upload trac does not work properly!

It always return the status after the upload has complete.

According to official data, it seems can’t work in PHP FastCGI mode.

So I took the site switch to normal CGI mode!

But still unable to achieve the effect I want!

So try the another uploadprogress components!

Which also takes a lot of time to adjust the configuration!

The original uploadprogress still can’t work in PHP fastcgi mode

And DH provided

To work properly!

(Here in fact, I went back to try the APC again… but still no solution)

But anyway, uploadprogress can be used, that I use it for now!