diff --git a/examples/SkylarkUpload/Handlers.icpp b/examples/SkylarkUpload/Handlers.icpp deleted file mode 100644 index 3aa819b62..000000000 --- a/examples/SkylarkUpload/Handlers.icpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "SkylarkUpload.h" - -int ProgressHandler(int reason, Http &http, int size) -{ - // get the upload unique identifier - String id = http["uploadid"]; - String currentId = "." + id + ".currentSize"; - String totalId = "." + id + ".totalSize"; - - // must be reentrant - INTERLOCKED { - switch(reason) - { - // got headers ? - case PROGRESS_HEADER: - { - http - .SessionSet(currentId, 0) - .SessionSet(totalId, size) - ; - break; - } - - // reading contents ? - case PROGRESS_CONTENT: - { - int oldPercent = http[currentId]; - int total = http[totalId]; - - // take care to NOT return 100% up to upload ended really - int percent = min(99, (int)(100.0 * size / total)); - - // avoid unnnedded session storing - if(oldPercent != percent) - http.SessionSet(currentId, percent); - break; - } - - // finished reading contents ? - case PROGRESS_END: - { - // signals end by resetting total size - http.SessionSet(totalId, 0); - break; - } - - // default, used by query handler - default: // PROGRESS_QUERY - { - // check if key is there --> upload started - int total = http[totalId]; - if(!IsNull(total)) - { - if(total) - // if upload not ended, return the progress % - return http[currentId]; - else - { - // upload ended, nullify session variables and return 100% - http - .SessionSet(currentId, Null) - .SessionSet(totalId, Null) - ; - return 100; - } - } - else - // upload still not started, return 0 progress - return 0; - } - } - } - return true; -} - -SKYLARK(Home, "home") -{ - // we need a session variable for upload id - if(http["@__skylark_session_cookie__"].IsNull()) - http.NewSessionId(); - - // show rootpath in html page - http("UploadFolder", Upload().GetRootPath()); - - http.RenderResult("SkylarkUpload/SkylarkUpload"); -} - -SKYLARK(Default, "**") -{ - http.Redirect(Home); -} - -SKYLARK_PROGRESS(PostUpload, "upload:POST", &ProgressHandler) -{ - String fileName = AppendFileName(Upload().GetRootPath(), (String)http["filename"]); - - Value const &contents = http["filestoupload[]"]; - Value const &filenames = http["filestoupload.filename[]"]; - if(contents.IsNull() || filenames.IsNull()) - return; - for(int i = 0; i < contents.GetCount(); i++) - SaveFile(AppendFileName(Upload().GetRootPath(), (String)filenames[i]), contents[i]); -} - -SKYLARK(Progress,"progress") -{ - int p = ProgressHandler(PROGRESS_QUERY, http, 0); - http.Content("text/plain", Format("%d", p)); - http.Response(200, "OK"); -} \ No newline at end of file diff --git a/examples/SkylarkUpload/SkylarkUpload.cpp b/examples/SkylarkUpload/SkylarkUpload.cpp deleted file mode 100644 index e04958c64..000000000 --- a/examples/SkylarkUpload/SkylarkUpload.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "SkylarkUpload.h" - - -SkylarkUpload &Upload() -{ - return (SkylarkUpload &)SkylarkApp::TheApp(); -} - -SkylarkUpload::SkylarkUpload(String const &rPath) -{ - root = "server"; - rootPath = rPath; - RealizeDirectory(rootPath); - -#ifdef _DEBUG - prefork = 0; - use_caching = false; -#endif - -} - -CONSOLE_APP_MAIN -{ -#ifdef _DEBUG - StdLogSetup(LOG_FILE|LOG_COUT); - Ini::skylark_log = true; -#endif - - SkylarkUpload upload(AppendFileName(GetHomeDirectory(), "UPLOAD/")); - - upload.Run(); - -} diff --git a/examples/SkylarkUpload/SkylarkUpload.css b/examples/SkylarkUpload/SkylarkUpload.css deleted file mode 100644 index 70bd4112f..000000000 --- a/examples/SkylarkUpload/SkylarkUpload.css +++ /dev/null @@ -1,36 +0,0 @@ -/* body container -- used just to center on screen */ -#bodyContainer { - text-align:center; - width:100%; - height:20em; - background-color:#eee; -} - -/* a fancy header */ -#header { - font-size:30px; - color:white; - background-color:blue; -} - -/* progress bar container -- sets the maximum bar width */ -#progress_container { - border: solid 1px #000; - height: 20px; - width: 300px; - text-align:center; - margin:0 auto; -} - -/* progress bar */ -#progress { - background-color: #006666; - color:white; - height: 20px; - width: 0px; -} - -/* progress and hidden frame not showing */ -#progress_container, #hidden_iframe { - display: none; -} diff --git a/examples/SkylarkUpload/SkylarkUpload.h b/examples/SkylarkUpload/SkylarkUpload.h deleted file mode 100644 index 5d2a50992..000000000 --- a/examples/SkylarkUpload/SkylarkUpload.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _SkylarkUpload_SkylarkUpload_h_ -#define _SkylarkUpload_SkylarkUpload_h_ - -#include - -using namespace Upp; - -class SkylarkUpload : public SkylarkApp -{ - private: - - // root path for saving files - String rootPath; - - protected: - - public: - - // constructor - SkylarkUpload(String const &rPath); - - // get root path - String const &GetRootPath(void) { return rootPath; } - -}; - -SkylarkUpload &Upload(); - -#endif diff --git a/examples/SkylarkUpload/SkylarkUpload.upp b/examples/SkylarkUpload/SkylarkUpload.upp deleted file mode 100644 index 91f7af20e..000000000 --- a/examples/SkylarkUpload/SkylarkUpload.upp +++ /dev/null @@ -1,17 +0,0 @@ -description "Skylark upload with ajax progress bar\377"; - -uses - Core, - Skylark; - -file - SkylarkUpload.h, - Handlers.icpp, - SkylarkUpload.cpp, - SkylarkUpload.witz, - SkylarkUpload.css, - upload.js; - -mainconfig - "" = "MT"; - diff --git a/examples/SkylarkUpload/SkylarkUpload.witz b/examples/SkylarkUpload/SkylarkUpload.witz deleted file mode 100644 index 0b86a449f..000000000 --- a/examples/SkylarkUpload/SkylarkUpload.witz +++ /dev/null @@ -1,76 +0,0 @@ - - - File Upload Progress Bar - - - - - - -
- - -
-
- This demo supports uploading multiple files at once -
- Files will be uploaded in '$UploadFolder' folder on server -
-
- - - - - - - -
- - - -

- -
-
- - -
-
-
- - - - - - - -
- - diff --git a/examples/SkylarkUpload/upload.js b/examples/SkylarkUpload/upload.js deleted file mode 100644 index 6cc9974cd..000000000 --- a/examples/SkylarkUpload/upload.js +++ /dev/null @@ -1,86 +0,0 @@ -// toggles progress bar visibility -function toggleBarVisibility() { - var e = document.getElementById("progress_container"); - e.style.display = (e.style.display == "block") ? "none" : "block"; -} - -// create http request object for upload -// browser dependent -- probably NOT completely cross browser -// if you use JQuery there are better ways -function createRequestObject() { - var http; - if (navigator.appName == "Microsoft Internet Explorer") { - http = new ActiveXObject("Microsoft.XMLHTTP"); - } - else { - http = new XMLHttpRequest(); - } - return http; -} - - -function sendRequest() { - var http = createRequestObject(); - - // use session cookie and current time to build an unique upload identifier - var session = document.getElementById('session').value; - var time = document.getElementById('submittime').value; - - // get upload url - var url = document.getElementById('progressurl').value; - - // build GET uri and do the request - http.open("GET", url + "?uploadid=" + session + time); - - // setup a callback handling end of request - http.onreadystatechange = function () { handleResponse(http); }; - http.send(null); -} - -// this callback handles 'progress' http requests results -function handleResponse(http) { - var response; - if (http.readyState == 4) { - response = http.responseText; - document.getElementById("progress").style.width = response + "%"; - document.getElementById("progress").innerHTML = response + "%"; - - if (response < 100) { - // if upload still not complete, repost a progress request after some time - // (here 200 msec) - setTimeout("sendRequest()", 200); - } - else { - // if progress is complete, put 'Done' inside bar, then - // run a callback that hides it after some time - document.getElementById("progress").innerHTML = "100% Done."; - - // hides 'Done' status - setTimeout("closeProgress()", 3000); - } - } -} - -// this callback hides status bar after some time upload is over -function closeProgress() { - toggleBarVisibility(); - document.getElementById("progress").innerHTML = ""; -} - -function startUpload(me) { - // sets an unique 'uploadid' field composed by session cookie and current time - var session = document.getElementById('session').value; - var time = Date.now(); - document.getElementById('submittime').value = time; - - // build upload URI adding the 'uploadid' variable - me.action = document.getElementById('uploadurl').value + '?uploadid=' + session + time; - - // setup progress bar - document.getElementById("progress").style.width = 0; - document.getElementById("progress").innerHTML = "0%"; - toggleBarVisibility(); - - // starts the delayed progress handler - setTimeout("sendRequest()", 200); -}