| xAjaxExtend для завантаження файлів | ||||
|
| Розробник |
|
Приклад використання xAjaxExtend для завантаження файлів. Якщо ви знаете що таке xAjax і для як і длячого його використовують то думаю небуде проблеми самому розібратися як це працює за допомогою прикладу
<?php $XAJAX_DIR = "xajax"; // Require the new xajax object require_once($XAJAX_DIR . "/xajaxExtend.php"); function uploadFiles(){ // (1) Create the response object $objResponse = new xajaxResponse(); // (2) Set the target path $target_path = ""; $i = 0; $uploading = ""; // (3) Go through the $_FILES array to get the uploaded files foreach ($_FILES as $key => $value) { if(move_uploaded_file($_FILES[$key]['tmp_name'], $target_path . basename( $_FILES[$key]['name']))) { $i++; $uploading .= "<li>" . basename( $_FILES[$key]['name']) . "</li>"; } } // (4) Prepare the response $result = "Uploaded files (" . $i . "): " . $uploading; $result .= "<p/><hr/>"; $objResponse->addAssign("uploadMessageDiv","innerHTML",$result); return $objResponse; } /** * Basic xajax calls here ... * Things to note are: * (1) Comment out the old xajax object, use the "extended" one * (2) Register the function above (you can also do a catch-all function) * (3) Call the processRequests() method as usual */ //$xajax = new xajax(); $xajax = new xajaxExtend; $xajax->registerFunction("uploadFiles"); $xajax->processRequests(); /** * HTML STARTS BELOW */ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd"> <html> <head> <title>xajax 0.2.4 File Upload Demo</title> <?php $xajax->printJavascript($XAJAX_DIR) ?> <script language="Javascript"> function checkUploadForm() { // You can do some checks here return xajax.upload('uploadFiles','uploadForm'); } </script> </head> <body> <h2>xajax 0.2.4 File Upload Demo</h2> <div id="uploadMessageDiv"></div> <div id="uploadFormDiv"> <form id="uploadForm" name="uploadForm" onsubmit="return checkUploadForm()" method="POST" enctype="multipart/form-data"> <input type="text" name="textBox1" value="This is some text"/><br/> <input type="file" name="somefile"/> (required)<br/> <input type="file" name="otherfile"/><br/> <input type="submit" value="Upload Files"/> </form> </div> </body> </html> |
| Останнє оновлення ( Субота, 23 червня 2007, 01:53 ) |



















