cvs: pear /HTML_Progress2/examples/ajax/upload MyUploadProgressMeterStatus.class.php apc5_upload1.php apc5_upload2.php auto_server.php degrade.jpg
http_upload.php pave-blanc-24.png
| From: | Laurent Laville | Date: | Mon, 12 Feb 2007 15:28:20 +0000 |
| Subject: | cvs: pear /HTML_Progress2/examples/ajax/upload MyUploadProgressMeterStatus.class.php apc5_upload1.php apc5_upload2.php auto_server.php degrade.jpg http_upload.php pave-blanc-24.png |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44625@lists.php.net to get a copy of this message | ||
farell Mon Feb 12 15:28:20 2007 UTC
Added files:
/pear/HTML_Progress2/examples/ajax/upload apc5_upload1.php
apc5_upload2.php
auto_server.php
degrade.jpg
http_upload.php
MyUploadProgressMeterStatus.class.php
pave-blanc-24.png
Log:
APC with PHP5 and AJAX upload examples
http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/apc5_upload1.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/apc5_upload1.php +++ pear/HTML_Progress2/examples/ajax/upload/apc5_upload1.php <?php /** * Basic example of AJAX file upload with HTML_Progress2, PHP 5.2+ and APC * * @version $Id: apc5_upload1.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public * @example examples/ajax/upload/apc5_upload1.php * AP5 basic upload source code * @link http://www.laurent-laville.org/img/progress/screenshot/apc5_upload1.png * screenshot (Image PNG, 315x127 pixels) 2,84 Kb */ // final destination of uploaded files $path = 'web_files/' ; // basic PHP function file upload handler if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (move_uploaded_file($_FILES['userfile']['tmp_name'], $path . $_FILES['userfile']['name'])) { $html_output = 'Upload finished'; echo '<pre>'; var_dump($_FILES); echo '</pre>'; } else { $html_output = 'Upload failed'; } } die($html_output); } require_once 'HTML/Progress2.php'; // build a very basic progress bar with default size and colors $pb = new HTML_Progress2(); $pb->setIdent('PB1'); // add default text label area to get current upload info $pb->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'uplStatus'); $pb->registerAJAX('auto_server.php', array('APC5UploadStatus')); // upload progress identifier : must be unique to avoid collision $progress_key = uniqid(); ?> <html> <head> <title>APC PHP5 AJAX Upload Progress Meter basic example </title> <script type="text/javascript" src="HTML_Progress2.js"></script> <?php echo $pb->setupAJAX(); ?> <script type="text/javascript"> //<![CDATA[ HTML_Progress2.serverClassName = 'APC5UploadStatus'; HTML_Progress2.serverMethodName = 'getStatus'; HTML_Progress2.requestArgs = 'upload_identifier=<?php echo $progress_key; ?>'; HTML_Progress2.onComplete = 'doUserAlert'; function doUserAlert() { alert('Upload file done !'); } //]]> </script> <style type="text/css"> <!-- <?php echo $pb->getStyle(); ?> body {background-color: #EEEEEE; } --> </style> </head> <body> <form enctype="multipart/form-data" target="tfrm" action="apc5_upload1.php" method="post" onsubmit="HTML_Progress2.start('<?php echo $pb->getIdent(); ?>', 500);"> <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $progress_key; ?>"> <input type="file" id="userfile" name="userfile"> <input type="submit" value="Upload!"> </form> <iframe id="tfrm" name="tfrm" style="width:1px;height:1px;border:0"></iframe> <?php $pb->display(); ?> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/apc5_upload2.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/apc5_upload2.php +++ pear/HTML_Progress2/examples/ajax/upload/apc5_upload2.php <?php /** * Custom example of AJAX file upload with HTML_Progress2, PHP 5.2+ and APC * * @version $Id: apc5_upload2.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public * @example examples/ajax/upload/apc5_upload2.php * AP5 basic upload source code * @link http://www.laurent-laville.org/img/progress/screenshot/apc5_upload2.png * screenshot (Image PNG, 590x153 pixels) 8,41 Kb */ require_once 'PEAR.php'; require_once 'HTML/Progress2.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); // build a progress bar without default percentage label $pb = new HTML_Progress2(null, HTML_PROGRESS2_BAR_HORIZONTAL, 0, 100, false); $pb->setIdent('PB1'); // will replace the default uplStatus label with formatted option (see auto_server.php) $pb->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'sizeStatus'); // will replace the default percentage label with formatted option (see auto_server.php) $pb->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'percentStatus'); $pb->setCellCount(15); $pb->setBorderPainted(true); $pb->setProgressAttributes(array( 'background-color' => 'transparent', 'background-image' => 'degrade.jpg', 'background-repeat' => 'repeat-y' )); $pb->setCellAttributes(array( 'active-color' => 'transparent', 'inactive-color' => 'transparent', 'height' => 40, 'width' => 35, 'background-image' => 'pave-blanc-24.png', 'background-position' => 'center center', )); $pb->setBorderAttributes(array( 'width' => 2, 'style' => 'solid', 'color' => 'red' )); $pb->setLabelAttributes('percentStatus', 'valign=top align=right width=550'); $pb->registerAJAX('auto_server.php', array('RequestAPC5Status')); // upload progress identifier : must be unique to avoid collision $progress_key = md5(uniqid(rand(), true)); ?> <html> <head> <title>APC PHP5 AJAX Upload Progress Meter custom example </title> <script type="text/javascript" src="HTML_Progress2.js"></script> <?php echo $pb->setupAJAX(); ?> <script type="text/javascript"> //<![CDATA[ HTML_Progress2.serverClassName = 'RequestAPC5Status'; HTML_Progress2.serverMethodName = 'getStatus'; HTML_Progress2.onComplete = 'doNothing'; function beginUpload() { HTML_Progress2.requestArgs = 'uploadID=<?php echo $progress_key; ?>'; HTML_Progress2.start('<?php echo $pb->getIdent(); ?>', 1000); } function doNothing() { } //]]> </script> <style type="text/css"> <!-- <?php echo $pb->getStyle(); ?> body {background-color: #EEEEEE; } --> </style> </head> <body> <form enctype="multipart/form-data" target="tfrm" action="http_upload.php" method="post" onsubmit="beginUpload();"> <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $progress_key; ?>"> <input type="file" id="userfile" name="userfile"> <input type="submit" value="Upload!"> </form> <iframe id="tfrm" name="tfrm" style="width:1px;height:1px;border:0"></iframe> <?php $pb->display(); ?> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/auto_server.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/auto_server.php +++ pear/HTML_Progress2/examples/ajax/upload/auto_server.php <?php /** * Auto server that will serve upload file informations * * @version $Id: auto_server.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public */ require_once 'HTML/AJAX/Server.php'; class AutoServer extends HTML_AJAX_Server { // this flag must be set for your init methods to be used var $initMethods = true; function initAPC5UploadStatus() { require_once 'HTML/Progress2/Upload.php'; $status = new HTML_Progress2_Upload(); $this->registerClass($status, 'APC5UploadStatus', array('getStatus')); } function initRequestAPC5Status() { require_once 'MyUploadProgressMeterStatus.class.php'; $format = array('sizeStatus' => '%C (%T)', 'percentStatus' => 'Uploading: please wait ... %P% done'); $status = new MyUploadProgressMeterStatus($format); $this->registerClass($status, 'RequestAPC5Status', array('getStatus')); } } $server = new AutoServer(); $server->handleRequest(); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/http_upload.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/http_upload.php +++ pear/HTML_Progress2/examples/ajax/upload/http_upload.php <?php /** * Basic file upload example that used PEAR::HTTP_Upload package facility * to handle uploaded files. * * @version $Id: http_upload.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public */ require_once 'PEAR.php'; require_once 'HTTP/Upload.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); $upload = new HTTP_Upload(); $file = $upload->getFiles('userfile'); if ($file->isValid()) { $file->setName('safe'); $dest_dir = 'web_files/'; $dest_name = $file->moveTo($dest_dir); } elseif ($file->isError()) { echo $file->errorMsg(); } else { echo '<pre>'; var_dump($file->getProp()); echo '</pre>'; } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/MyUploadProgressMeterStatus.class.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/MyUploadProgressMeterStatus.class.php +++ pear/HTML_Progress2/examples/ajax/upload/MyUploadProgressMeterStatus.class.php <?php /** * Custom backend example of AJAX file upload with HTML_Progress2, PHP 5.2+ and APC * * @version $Id: MyUploadProgressMeterStatus.class.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public */ require_once 'HTML/Progress2/Upload.php'; /** * This class show how to use a custom upload identifier * through the query string (see also apc5_upload2.php, HTML_Progress2.requestArgs) * and handle progress bar labels values. */ class MyUploadProgressMeterStatus extends HTML_Progress2_Upload { function MyUploadProgressMeterStatus($format = null) { parent::__construct($format); } function getStatus($uplId = null) { if (!isset($uplId)) { $uplId = $_GET['uploadID']; } $tmp = $this->getInfo($uplId); $ret = parent::getStatus($uplId); if (is_array($ret) && $ret['percentage'] == 100) { $ret['labels']['percentStatus'] = 'Upload done !'; } return $ret; } } ?>
http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/apc5_upload1.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/apc5_upload1.php +++ pear/HTML_Progress2/examples/ajax/upload/apc5_upload1.php <?php /** * Basic example of AJAX file upload with HTML_Progress2, PHP 5.2+ and APC * * @version $Id: apc5_upload1.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public * @example examples/ajax/upload/apc5_upload1.php * AP5 basic upload source code * @link http://www.laurent-laville.org/img/progress/screenshot/apc5_upload1.png * screenshot (Image PNG, 315x127 pixels) 2,84 Kb */ // final destination of uploaded files $path = 'web_files/' ; // basic PHP function file upload handler if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (move_uploaded_file($_FILES['userfile']['tmp_name'], $path . $_FILES['userfile']['name'])) { $html_output = 'Upload finished'; echo '<pre>'; var_dump($_FILES); echo '</pre>'; } else { $html_output = 'Upload failed'; } } die($html_output); } require_once 'HTML/Progress2.php'; // build a very basic progress bar with default size and colors $pb = new HTML_Progress2(); $pb->setIdent('PB1'); // add default text label area to get current upload info $pb->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'uplStatus'); $pb->registerAJAX('auto_server.php', array('APC5UploadStatus')); // upload progress identifier : must be unique to avoid collision $progress_key = uniqid(); ?> <html> <head> <title>APC PHP5 AJAX Upload Progress Meter basic example </title> <script type="text/javascript" src="HTML_Progress2.js"></script> <?php echo $pb->setupAJAX(); ?> <script type="text/javascript"> //<![CDATA[ HTML_Progress2.serverClassName = 'APC5UploadStatus'; HTML_Progress2.serverMethodName = 'getStatus'; HTML_Progress2.requestArgs = 'upload_identifier=<?php echo $progress_key; ?>'; HTML_Progress2.onComplete = 'doUserAlert'; function doUserAlert() { alert('Upload file done !'); } //]]> </script> <style type="text/css"> <!-- <?php echo $pb->getStyle(); ?> body {background-color: #EEEEEE; } --> </style> </head> <body> <form enctype="multipart/form-data" target="tfrm" action="apc5_upload1.php" method="post" onsubmit="HTML_Progress2.start('<?php echo $pb->getIdent(); ?>', 500);"> <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $progress_key; ?>"> <input type="file" id="userfile" name="userfile"> <input type="submit" value="Upload!"> </form> <iframe id="tfrm" name="tfrm" style="width:1px;height:1px;border:0"></iframe> <?php $pb->display(); ?> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/apc5_upload2.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/apc5_upload2.php +++ pear/HTML_Progress2/examples/ajax/upload/apc5_upload2.php <?php /** * Custom example of AJAX file upload with HTML_Progress2, PHP 5.2+ and APC * * @version $Id: apc5_upload2.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public * @example examples/ajax/upload/apc5_upload2.php * AP5 basic upload source code * @link http://www.laurent-laville.org/img/progress/screenshot/apc5_upload2.png * screenshot (Image PNG, 590x153 pixels) 8,41 Kb */ require_once 'PEAR.php'; require_once 'HTML/Progress2.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); // build a progress bar without default percentage label $pb = new HTML_Progress2(null, HTML_PROGRESS2_BAR_HORIZONTAL, 0, 100, false); $pb->setIdent('PB1'); // will replace the default uplStatus label with formatted option (see auto_server.php) $pb->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'sizeStatus'); // will replace the default percentage label with formatted option (see auto_server.php) $pb->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'percentStatus'); $pb->setCellCount(15); $pb->setBorderPainted(true); $pb->setProgressAttributes(array( 'background-color' => 'transparent', 'background-image' => 'degrade.jpg', 'background-repeat' => 'repeat-y' )); $pb->setCellAttributes(array( 'active-color' => 'transparent', 'inactive-color' => 'transparent', 'height' => 40, 'width' => 35, 'background-image' => 'pave-blanc-24.png', 'background-position' => 'center center', )); $pb->setBorderAttributes(array( 'width' => 2, 'style' => 'solid', 'color' => 'red' )); $pb->setLabelAttributes('percentStatus', 'valign=top align=right width=550'); $pb->registerAJAX('auto_server.php', array('RequestAPC5Status')); // upload progress identifier : must be unique to avoid collision $progress_key = md5(uniqid(rand(), true)); ?> <html> <head> <title>APC PHP5 AJAX Upload Progress Meter custom example </title> <script type="text/javascript" src="HTML_Progress2.js"></script> <?php echo $pb->setupAJAX(); ?> <script type="text/javascript"> //<![CDATA[ HTML_Progress2.serverClassName = 'RequestAPC5Status'; HTML_Progress2.serverMethodName = 'getStatus'; HTML_Progress2.onComplete = 'doNothing'; function beginUpload() { HTML_Progress2.requestArgs = 'uploadID=<?php echo $progress_key; ?>'; HTML_Progress2.start('<?php echo $pb->getIdent(); ?>', 1000); } function doNothing() { } //]]> </script> <style type="text/css"> <!-- <?php echo $pb->getStyle(); ?> body {background-color: #EEEEEE; } --> </style> </head> <body> <form enctype="multipart/form-data" target="tfrm" action="http_upload.php" method="post" onsubmit="beginUpload();"> <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $progress_key; ?>"> <input type="file" id="userfile" name="userfile"> <input type="submit" value="Upload!"> </form> <iframe id="tfrm" name="tfrm" style="width:1px;height:1px;border:0"></iframe> <?php $pb->display(); ?> </body> </html> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/auto_server.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/auto_server.php +++ pear/HTML_Progress2/examples/ajax/upload/auto_server.php <?php /** * Auto server that will serve upload file informations * * @version $Id: auto_server.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public */ require_once 'HTML/AJAX/Server.php'; class AutoServer extends HTML_AJAX_Server { // this flag must be set for your init methods to be used var $initMethods = true; function initAPC5UploadStatus() { require_once 'HTML/Progress2/Upload.php'; $status = new HTML_Progress2_Upload(); $this->registerClass($status, 'APC5UploadStatus', array('getStatus')); } function initRequestAPC5Status() { require_once 'MyUploadProgressMeterStatus.class.php'; $format = array('sizeStatus' => '%C (%T)', 'percentStatus' => 'Uploading: please wait ... %P% done'); $status = new MyUploadProgressMeterStatus($format); $this->registerClass($status, 'RequestAPC5Status', array('getStatus')); } } $server = new AutoServer(); $server->handleRequest(); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/http_upload.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/http_upload.php +++ pear/HTML_Progress2/examples/ajax/upload/http_upload.php <?php /** * Basic file upload example that used PEAR::HTTP_Upload package facility * to handle uploaded files. * * @version $Id: http_upload.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public */ require_once 'PEAR.php'; require_once 'HTTP/Upload.php'; PEAR::setErrorHandling(PEAR_ERROR_DIE); $upload = new HTTP_Upload(); $file = $upload->getFiles('userfile'); if ($file->isValid()) { $file->setName('safe'); $dest_dir = 'web_files/'; $dest_name = $file->moveTo($dest_dir); } elseif ($file->isError()) { echo $file->errorMsg(); } else { echo '<pre>'; var_dump($file->getProp()); echo '</pre>'; } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_Progress2/examples/ajax/upload/MyUploadProgressMeterStatus.class.php?view=markup&rev=1.1 Index: pear/HTML_Progress2/examples/ajax/upload/MyUploadProgressMeterStatus.class.php +++ pear/HTML_Progress2/examples/ajax/upload/MyUploadProgressMeterStatus.class.php <?php /** * Custom backend example of AJAX file upload with HTML_Progress2, PHP 5.2+ and APC * * @version $Id: MyUploadProgressMeterStatus.class.php,v 1.1 2007/02/12 15:28:20 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples * @access public */ require_once 'HTML/Progress2/Upload.php'; /** * This class show how to use a custom upload identifier * through the query string (see also apc5_upload2.php, HTML_Progress2.requestArgs) * and handle progress bar labels values. */ class MyUploadProgressMeterStatus extends HTML_Progress2_Upload { function MyUploadProgressMeterStatus($format = null) { parent::__construct($format); } function getStatus($uplId = null) { if (!isset($uplId)) { $uplId = $_GET['uploadID']; } $tmp = $this->getInfo($uplId); $ret = parent::getStatus($uplId); if (is_array($ret) && $ret['percentage'] == 100) { $ret['labels']['percentStatus'] = 'Upload done !'; } return $ret; } } ?>