{"id":20208222,"url":"https://github.com/cubiclesoft/php-cool-file-transfer","last_synced_at":"2025-06-11T21:36:27.285Z","repository":{"id":145129404,"uuid":"99532139","full_name":"cubiclesoft/php-cool-file-transfer","owner":"cubiclesoft","description":"Directly transfer files between two devices (PC, tablet, smartphone, refridgerator) using nothing more than a web browser and a standard PHP enabled web server.  MIT or LGPL.","archived":false,"fork":false,"pushed_at":"2022-10-21T02:38:34.000Z","size":196,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T11:44:35.727Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cubiclesoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/cft.css","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-07T03:16:03.000Z","updated_at":"2024-11-12T15:33:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"ddd5c065-06cd-4989-b021-907dc17ef3fa","html_url":"https://github.com/cubiclesoft/php-cool-file-transfer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-cool-file-transfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-cool-file-transfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-cool-file-transfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cubiclesoft%2Fphp-cool-file-transfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cubiclesoft","download_url":"https://codeload.github.com/cubiclesoft/php-cool-file-transfer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248221696,"owners_count":21067605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T05:34:36.478Z","updated_at":"2025-04-10T12:54:56.959Z","avatar_url":"https://github.com/cubiclesoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Cool File Transfer\n==================\n\nDirectly transfer files between two devices using nothing more than a web browser and a standard PHP enabled web server.  Choose from a MIT or LGPL license.\n\nInstead of using third-party services such as Dropbox or Google Drive to transfer files, Cool File Transfer directly transfers files through a host that both devices have access to.  It's great for moving large files without requiring intermediate storage!\n\nYour PC, tablet, smartphone, refridgerator, and IT department thank you for choosing Cool File Transfer.\n\n[![Awesome demo of Cool File Transfer](https://user-images.githubusercontent.com/1432111/29055577-1d21076c-7bb2-11e7-86bd-a46b825ecf27.png)](https://www.youtube.com/watch?v=haWIVLhefnA \"Awesome demo of Cool File Transfer\")\n\n[![Donate](https://cubiclesoft.com/res/donate-shield.png)](https://cubiclesoft.com/donate/) [![Discord](https://img.shields.io/discord/777282089980526602?label=chat\u0026logo=discord)](https://cubiclesoft.com/product-support/github/)\n\nFeatures\n--------\n\n* Transfer files of any size.\n* Unlimited user ecosystem.\n* Beautiful, elegant user interface.\n* Easy integration into websites (e.g. Intranets).\n* Uploading works on any device with a relatively modern-ish Javascript enabled web browser that has HTML 5 blob support.\n* Downloading works on any device/web browser that supports downloading files.\n* Can be used as the basis of a script that automatically picks up and processes content streams as they upload but without storing anything to disk.\n* Fabulous 2-minute installer.\n* Multilingual support.\n* Has a liberal open source license.  MIT or LGPL, your choice.\n* Designed for relatively painless integration into your environment.\n* Sits on GitHub for all of that pull request and issue tracker goodness to easily submit changes and ideas respectively.\n\nGetting Started\n---------------\n\nPut the contents of this repository on a web server running PHP.  Then run the `install.php` file using your web browser.  SQLite is a great starting database that sets up quickly but MySQL and Postgres are supported too.  Assuming you have a decent setup, the installer takes only a couple of minutes.\n\nOnce Cool File Transfer is installed, secure the installation path and then start using it.  A nifty class that is creatively called `CoolFileTransfer` is inside `cft.php`.  It's designed to be an intermediate, isolated layer between the configuration (config.php), the database, and an application (or API).  Also included with Cool File Transfer is [jQuery Fancy File Uploader](https://github.com/cubiclesoft/jquery-fancyfileuploader).  Let's use the `CoolFileTransfer` class to display a file transfer dropzone:\n\n```php\n\u003c?php\n\trequire_once \"/var/www/cool-file-transfer/cft.php\";\n\n\t$cft = new CoolFileTransfer();\n\n\t$srcuser = \"The Webmaster (webmaster@cubiclesoft.com)\";\n\n\tif (isset($_REQUEST[\"action\"]) \u0026\u0026 $_REQUEST[\"action\"] === \"starttransfer\")\n\t{\n\t\tif (!isset($_REQUEST[\"destuser\"]) || !isset($_REQUEST[\"filename\"]) || !isset($_REQUEST[\"filesize\"]))\n\t\t{\n\t\t\t$result = array(\n\t\t\t\t\"success\" =\u003e false,\n\t\t\t\t\"error\" =\u003e \"Missing 'destuser', 'filename', or 'filesize'.\",\n\t\t\t\t\"errorcode\" =\u003e \"missing_required_fields\"\n\t\t\t);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t$result = $cft-\u003eStartSendFile($srcuser, $_REQUEST[\"destuser\"], $_REQUEST[\"filename\"], $_REQUEST[\"filesize\"]);\n\t\t}\n\n\t\theader(\"Content-Type: application/json\");\n\n\t\techo json_encode($result, JSON_UNESCAPED_SLASHES);\n\t}\n\telse\n\t{\n\t\t// Obviously, you'll use something more dynamic for production use.\n\t\t$destuser = \"Bob (bob@forapples.com)\";\n\n\t\trequire_once \"/var/www/cool-file-transfer/support/flex_forms.php\";\n\t\trequire_once \"/var/www/cool-file-transfer/support/flex_forms_fileuploader.php\";\n?\u003e\n\u003cdiv class=\"fileuploadwrap\"\u003e\u003cinput class=\"text\" type=\"file\" id=\"uploader\" name=\"file\" /\u003e\u003c/div\u003e\n\n\u003cscript type=\"text/javascript\" src=\"/cool-file-transfer/support/jquery-3.5.0.min.js\"\u003e\u003c/script\u003e\n\n\u003clink rel=\"stylesheet\" href=\"/cool-file-transfer/support/fancy-file-uploader/fancy_fileupload.css\" type=\"text/css\" media=\"all\" /\u003e\n\u003cscript type=\"text/javascript\" src=\"/cool-file-transfer/support/fancy-file-uploader/jquery.ui.widget.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"/cool-file-transfer/support/fancy-file-uploader/jquery.fileupload.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"/cool-file-transfer/support/fancy-file-uploader/jquery.iframe-transport.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"/cool-file-transfer/support/fancy-file-uploader/jquery.fancy-fileupload.js\"\u003e\u003c/script\u003e\n\n\u003cscript type=\"text/javascript\" src=\"\u003c?php echo $cft-\u003eGetDefaultJS(); ?\u003e\"\u003e\u003c/script\u003e\n\n\u003cscript type=\"text/javascript\"\u003e\njQuery(function() {\n\tvar options = {\n\t\t'fileupload' : {\n\t\t\t'maxChunkSize' : \u003c?php echo FlexForms_FileUploader::GetMaxUploadFileSize(); ?\u003e\n\t\t},\n\t\t'preinit' : CoolFileTransfer.PreInit,\n\t\t'startupload' : CoolFileTransfer.StartUpload,\n\t\t'uploadcancelled' : CoolFileTransfer.UploadCancelled\n\t};\n\n\tjQuery('#uploader').FancyFileUpload(options);\n});\n\u003c/script\u003e\n\n\u003cscript type=\"text/javascript\"\u003e\nCoolFileTransfer.targeturl = '/yourapp/';\n\nCoolFileTransfer.initrequest = {\n\t'action' : 'starttransfer',\n\t'destuser' : '\u003c?php echo FlexForms::JSSafe($destuser); ?\u003e',\n\t'xsrf_token' : 'your_xsrf_token_here'\n};\n\u003c/script\u003e\n\u003c?php\n\t}\n?\u003e\n```\n\nOkay, that's half of the equation.  That puts the uploader widget onto a page.  Target users have to be aware that there is a file waiting for them, so the `CoolFileTransfer` class makes it easy to display notifications to users:\n\n```php\n\trequire_once \"/var/www/cool-file-transfer/cft.php\";\n\n\t$cft = new CoolFileTransfer();\n\n\t$srcuser = \"Bob (bob@forapples.com)\";\n\n\t// Retrieve the notification list.\n\t$result = $cft-\u003eGetRecvList($srcuser);\n\tif ($result[\"success\"] \u0026\u0026 count($result[\"users\"]))\n\t{\n?\u003e\n\u003clink rel=\"stylesheet\" href=\"\u003c?=$cft-\u003eGetDefaultCSS()?\u003e\" type=\"text/css\" media=\"all\" /\u003e\n\u003c?php\n\t\t$cft-\u003eOutputHTMLNotifications($result[\"users\"]);\n\t}\n```\n\nJust put that code somewhere before the closing `body` tag in your HTML and your users will see nice notification boxes whenever a file is ready to transfer.\n\nOptions\n-------\n\nThe default Javascript implementation of Cool File Transfer accepts the following options:\n\n* targeturl - A URL to send a request to in order to initiate a file transfer.  The destination server is expected to return a valid result containing target URLs and tokens from `$cft-\u003eStartSendFile()` or a standard error JSON object (Default is '').\n* initrequest - A Javascript object that contains additional information to pass to the server during the initial request for a token.  This can be used to pass along information such as the user to send the file to (Default is an empty object).\n* langmap - An object containing translation strings.  Support exists for most of the user interface (Default is an empty object).\n\nHow it Works\n------------\n\nOther than PHP's default behavior for file handling, Cool File Transfer doesn't store file data to disk.  Instead, the sending and receiving endpoints set up and connect to TCP/IP servers at various times to perform the necessary communication between two separate PHP processes.  Most third-party services store a file upload until the recipient comes along and retrieves it.  However, doing that requires storage space, which may or may not be feasible.  Regardless, Cool File Transfer is a very different tool.\n\nThe sending side attempts to self-regulate its speed to a bitrate of 1.25 seconds of transferred data per request.  This allows both sides to send and receive data at roughly the same rate during a lengthy transfer process.  Since most web browsers will use keep-alive connections, a little extra overhead is fine.  This approach prevents stalling either side for any significant amount of time.\n\nFun Facts\n---------\n\nThis product uses a LOT of existing CubicleSoft software (FlexForms, FlexForms Modules, CSDB, jQuery Fancy File Uploader, and some previously unpublished code).  Completing the entire project in one weekend would not have been feasible without the existing technology stack.\n\nYou read that right:  This entire project was produced in just one weekend.  Fully releasing everything to the Interwebs took another day though, but only because making a video to showcase a project takes time.\n\nAdmin Pack/FlexForms Integration\n--------------------------------\n\nIf you use [Admin Pack](https://github.com/cubiclesoft/admin-pack-with-extras), then you can integrate the first half like this:\n\n```php\n\u003c?php\n\trequire_once \"/var/www/cool-file-transfer/cft.php\";\n\n\t$cft = new CoolFileTransfer();\n\n\t$srcuser = \"The Webmaster (webmaster@cubiclesoft.com)\";\n\n\tif (isset($_REQUEST[\"action\"]) \u0026\u0026 $_REQUEST[\"action\"] === \"starttransfer\")\n\t{\n\t\tif (!isset($_REQUEST[\"destuser\"]) || !isset($_REQUEST[\"filename\"]) || !isset($_REQUEST[\"filesize\"]))\n\t\t{\n\t\t\t$result = array(\n\t\t\t\t\"success\" =\u003e false,\n\t\t\t\t\"error\" =\u003e \"Missing 'destuser', 'filename', or 'filesize'.\",\n\t\t\t\t\"errorcode\" =\u003e \"missing_required_fields\"\n\t\t\t);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t$result = $cft-\u003eStartSendFile($srcuser, $_REQUEST[\"destuser\"], $_REQUEST[\"filename\"], $_REQUEST[\"filesize\"]);\n\t\t}\n\n\t\theader(\"Content-Type: application/json\");\n\n\t\techo json_encode($result, JSON_UNESCAPED_SLASHES);\n\t}\n\telse\n\t{\n\t\t// Obviously, you'll use something more dynamic for production use.\n\t\t$destuser = \"Bob (bob@forapples.com)\";\n\n\t\trequire_once \"support/flex_forms_fileuploader.php\";\n\n\t\t$desc = \"\u003cbr\u003e\";\n\n\t\tob_start();\n?\u003e\n\u003cscript type=\"text/javascript\" src=\"\u003c?php echo $cft-\u003eGetDefaultJS(); ?\u003e\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\nCoolFileTransfer.targeturl = '\u003c?php echo BB_JSSafe(BB_GetRequestURLBase()); ?\u003e';\n\nCoolFileTransfer.initrequest = {\n\t'action' : 'starttransfer',\n\t'destuser' : '\u003c?php echo BB_JSSafe($destuser); ?\u003e',\n\t'sec_t' : '\u003c?php echo BB_CreateSecurityToken(\"starttransfer\"); ?\u003e'\n};\n\u003c/script\u003e\n\u003c?php\n\t\t$desc .= ob_get_contents();\n\t\tob_end_clean();\n\n\t\t$contentopts = array(\n\t\t\t\"desc\" =\u003e \"You are signed in as '\" . $srcuser . \"'.  Send files to '\" . $destuser . \"'.\",\n\t\t\t\"htmldesc\" =\u003e $desc,\n\t\t\t\"fields\" =\u003e array(\n\t\t\t\tarray(\n\t\t\t\t\t\"type\" =\u003e \"file\",\n\t\t\t\t\t\"name\" =\u003e \"file\",\n\t\t\t\t\t\"uploader\" =\u003e true,\n\t\t\t\t\t\"maxchunk\" =\u003e FlexForms_FileUploader::GetMaxUploadFileSize(),\n\t\t\t\t\t\"uploader_callbacks\" =\u003e array(\n\t\t\t\t\t\t\"preinit\" =\u003e \"CoolFileTransfer.PreInit\",\n\t\t\t\t\t\t\"startupload\" =\u003e \"CoolFileTransfer.StartUpload\",\n\t\t\t\t\t\t\"uploadcancelled\" =\u003e \"CoolFileTransfer.UploadCancelled\"\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\n\t\tBB_GeneratePage(\"Transfer Files\", $menuopts, $contentopts);\n\t}\n```\n\nFor [FlexForms Extras](https://github.com/cubiclesoft/php-flexforms-extras), the above will be similar but use the usual `$ff-\u003eGenerate($contentopts)` method.\n\nTo implement the second half in Admin Pack, abusing FlexForms CSS dependency injection via `BB_InjectLayoutHead()` is the easiest way to get Cool File Transfer notifications to appear regardless of where the user is located in the application:\n\n```php\n\u003c?php\n\tfunction BB_InjectLayoutHead()\n\t{\n\t\tglobal $cft, $srcuser, $bb_flexforms;\n\n\t\t// Menu title underline:  Colors with 60% saturation and 75% brightness generally look good.\n?\u003e\n\u003cstyle type=\"text/css\"\u003e\n#menuwrap .menu .title { border-bottom: 2px solid #C48851; }\n\n#contentwrap.showmenu .cft_notifications_wrap { display: none; }\n\u003c/style\u003e\n\u003c?php\n\n\t\t// Retrieve the notification list.\n\t\t$result = $cft-\u003eGetRecvList($srcuser);\n\t\tif ($result[\"success\"] \u0026\u0026 count($result[\"users\"]))\n\t\t{\n\t\t\t// Add everything to the FlexForms instance by (ab)using CSS options.\n\t\t\t$bb_flexforms-\u003eAddCSS(\"cft-default\", array(\"mode\" =\u003e \"link\", \"dependency\" =\u003e false, \"src\" =\u003e $cft-\u003eGetDefaultCSS()));\n\n\t\t\tob_start();\n\t\t\t$cft-\u003eOutputHTMLNotifications($result[\"users\"]);\n\n\t\t\t$bb_flexforms-\u003eAddCSS(\"cft-notifications\", array(\"mode\" =\u003e \"inline\", \"dependency\" =\u003e \"cft-default\", \"src\" =\u003e ob_get_contents()));\n\t\t\tob_end_clean();\n\t\t}\n\t}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubiclesoft%2Fphp-cool-file-transfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcubiclesoft%2Fphp-cool-file-transfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcubiclesoft%2Fphp-cool-file-transfer/lists"}