Permalink
Browse files

Added support for session.upload_progress as APC replacement

APC is no longer available as of PHP 5.4, Zoph uses APC to track upload
progress. Fortunately, PHP 5.4 also introduced session.upload_progress
to track upload progress. This change makes Zoph automatically select
either of the two ways, depending on the currently running version of
PHP.

fixes #39
  • Loading branch information...
1 parent bd3c458 commit ee2e4dd1bddba2364ea8a272a53607f92847efc3 @jeroenrnl committed Jul 11, 2013
Showing with 59 additions and 32 deletions.
  1. +8 −7 php/import.php
  2. +3 −1 php/requirements.inc.php
  3. +1 −1 php/templates/default/{ → blocks}/uploadform.tpl.php
  4. +0 −7 php/util.inc.php
  5. +47 −16 php/webimport.inc.php
View
@@ -26,7 +26,7 @@
// Detect upload larger than upload_max_filesize.
if(isset($_GET["upload"]) && $_GET["upload"]==1 && $_POST==null) {
- echo webImport::handleUploadErrors(UPLOAD_ERR_INI_SIZE);
+ echo WebImport::handleUploadErrors(UPLOAD_ERR_INI_SIZE);
die();
}
$_action=getvar("_action");
@@ -80,10 +80,11 @@
if(conf::get("import.upload")) {
$upload_num = $upload_id . "_" . $num;
- $body=new template("uploadform", array(
- "action" => "import.php?upload=1",
- "onsubmit" => "zImport.startUpload(this, upload_id, num); return true",
- "num" => $num,
+ $body=new block("uploadform", array(
+ "progress" => WebImport::getProgressName(),
+ "action" => "import.php?upload=1",
+ "onsubmit" => "zImport.startUpload(this, upload_id, num); return true",
+ "num" => $num,
"upload_num" => $upload_num));
$tpl=new template("html", array(
@@ -113,9 +114,9 @@
if($_FILES["file"]) {
$file=$_FILES["file"];
}
- $upload_num=getvar("APC_UPLOAD_PROGRESS");
+ $upload_num=getvar(WebImport::getProgressName());
- webImport::processUpload($file);
+ WebImport::processUpload($file);
$body=new template("uploadprogressbar", array(
"name" => $file["name"],
View
@@ -45,5 +45,7 @@
ini_set("magic_quotes_gpc", false);
ini_set("session.use_only_cookies", true);
-
+if(PHP_VERSION_ID < 50300) {
+ die("You should run at least PHP 5.3 to use Zoph");
+}
@@ -27,7 +27,7 @@
?>
<form enctype="multipart/form-data" action="<?php echo $tpl_action; ?>" method="POST"
onSubmit="<?php echo $tpl_onsubmit; ?>">
- <input type="hidden" name="APC_UPLOAD_PROGRESS"
+ <input type="hidden" name="<?php echo $tpl_progress ?>"
id="upload_<?php echo $tpl_num; ?>"
value="<?php echo $tpl_upload_num ?>">
<input type="hidden" name="_action" value="upload">
View
@@ -298,13 +298,6 @@ function create_form($vars, $ignore = array()) {
return $form;
}
-function minimum_version($vercheck) {
- $minver = (int)str_replace('.', '', $vercheck);
- $curver = (int)str_replace('.', '', phpversion());
- return ($curver >= $minver);
-}
-
-
function make_title($string) {
$string = str_replace("_", " ", $string);
$string = preg_replace("/\b(\w)/e", "strtoupper('\\1')", $string);
View
@@ -174,7 +174,7 @@ public static function processFile($md5) {
$dir=conf::get("path.images") . "/" . conf::get("path.upload") . "/";
$file=file::getFromMD5($dir, $md5);
-
+
if($file instanceof file) {
$mime=$file->getMime();
$type=$file->type;
@@ -346,24 +346,42 @@ public static function getProgressXML($uploadId) {
$node=$xml->createElement(self::XMLNODE);
- if(function_exists("apc_fetch")) {
- $progress=apc_fetch("upload_" . $uploadId);
- if($progress===false) {
+ if(PHP_VERSION_ID < 50400) {
+ if(function_exists("apc_fetch")) {
+ $progress=apc_fetch("upload_" . $uploadId);
+ if($progress===false) {
+ $progress['current']=0;
+ $progress['total']=0;
+ // probably something wrong with APC settings
+ if(ini_get("apc.enabled")==false) {
+ $progress['filename']="Enable apc.enabled in php.ini";
+ } else if(ini_get("apc.rfc1867")==false) {
+ $progress['filename']="Enable apc.rfc1867 in php.ini";
+ }
+ }
+ } else {
+ // APC extension not available
$progress['current']=0;
$progress['total']=0;
- // probably something wrong with APC settings
- if(ini_get("apc.enabled")==false) {
- $progress['filename']="Enable apc.enabled in PHP.ini";
- } else if(ini_get("apc.rfc1867")==false) {
- $progress['filename']="Enable apc.rfc1867 in PHP.ini";
- }
- }
+ $progress['filename']="APC extension not available";
+ }
} else {
- // APC extension not available
- $progress['current']=0;
- $progress['total']=0;
- $progress['filename']="APC extension not available";
+ if (ini_get("session.upload_progress.enabled")==true) {
+ $upl_prog=$_SESSION[ini_get("session.upload_progress.prefix") . $uploadId];
+ $progress['current']=$upl_prog["bytes_processed"];
+ $progress['total']=$upl_prog["content_length"];
+ // for now we take the first file as multiple uploads
+ // are not yet supported
+ $progress['filename']=$upl_prog["files"][0]["name"];
+ } else {
+ // session.upload_progress not enables extension not available
+ $progress['current']=0;
+ $progress['total']=0;
+ $progress['filename']="Enable session.upload_progress.enabled in php.ini";
+ }
+
}
+
$id=$xml->createElement("id");
$current=$xml->createElement("current");
$total=$xml->createElement("total");
@@ -406,7 +424,7 @@ public static function getThumbsXML() {
case "image":
$thumb=THUMB_PREFIX . DIRECTORY_SEPARATOR . THUMB_PREFIX . "_" . $file->getName();
$mid=MID_PREFIX . DIRECTORY_SEPARATOR . MID_PREFIX . "_" . $file->getName();
- if(file_exists($dir . $thumb) &&
+ if(file_exists($dir . DIRECTORY_SEPARATOR . $thumb) &&
file_exists($dir . DIRECTORY_SEPARATOR . $mid)) {
$status="done";
} else {
@@ -501,6 +519,19 @@ public static function getFileList(Array $import) {
return false;
}
}
+
+ /**
+ * Get the name of the progress hidden input field
+ * The name of this field differs based on the way progress is checked
+ * APC (PHP5.3) or session.import_progress (PHP>=5.4)
+ */
+ public static function getProgressName() {
+ if(PHP_VERSION_ID < 50400) {
+ return "APC_UPLOAD_PROGRESS";
+ } else {
+ return ini_get("session.upload_progress.name");
+ }
+ }
}
?>

0 comments on commit ee2e4dd

Please sign in to comment.