{"id":22974429,"url":"https://github.com/diversen/http-send-file","last_synced_at":"2025-04-09T19:19:00.345Z","repository":{"id":28052726,"uuid":"31548950","full_name":"diversen/http-send-file","owner":"diversen","description":"PHP lib which sends a file with support for (multiple) range requests and throttle. ","archived":false,"fork":false,"pushed_at":"2024-03-03T14:40:52.000Z","size":151,"stargazers_count":56,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-09T19:18:55.995Z","etag":null,"topics":["http-send-file"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diversen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-02T16:09:38.000Z","updated_at":"2024-11-18T09:14:38.000Z","dependencies_parsed_at":"2024-06-18T17:11:33.528Z","dependency_job_id":null,"html_url":"https://github.com/diversen/http-send-file","commit_stats":{"total_commits":51,"total_committers":5,"mean_commits":10.2,"dds":0.0980392156862745,"last_synced_commit":"3c13e086990dba7087f86c55118c44ff27ad59b6"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diversen%2Fhttp-send-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diversen%2Fhttp-send-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diversen%2Fhttp-send-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diversen%2Fhttp-send-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diversen","download_url":"https://codeload.github.com/diversen/http-send-file/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094990,"owners_count":21046770,"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":["http-send-file"],"created_at":"2024-12-15T00:00:41.366Z","updated_at":"2025-04-09T19:19:00.315Z","avatar_url":"https://github.com/diversen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP send file\n\nSends a file with support for (multiple) range requests. \nIt is able to throttle the download and adds an etag to the request.\nIt is quite small and simple.\n\n# Install\n\nWith composer add to your \"require\" section: \n\n    composer require diversen/http-send-file\n\nUsage example: \n\n~~~php\n\nuse Diversen\\Sendfile;\n$s = new Sendfile();\n        \n// if you don't set type - we will try to guess it\n$s-\u003esetContentType('application/epub+zip');\n        \n// if you don't set disposition (file name user agent will see)\n// we will make a file name from file\n$s-\u003esetContentDisposition('test.epub');\n\n// Expires header. Default is a date in the past\n$s-\u003esetExpires(3600);\n        \n// chunks of 40960 bytes per 0.1 secs\n// if you don't set this then the values below are the defaults\n// approx 40960 bytes per sec\n$s-\u003ethrottle(0.1, 40960);\n\n// file\n$file = '/some/dir/test.epub';\n\n// send the file\ntry {\n    $s-\u003esend($file);\n} catch (\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n\n~~~\n\nSo you could just do like this: \n\n~~~php\n\nuse Diversen\\Sendfile;\n$s = new Sendfile();\n\n// file\n$file = '/some/dir/test.epub';\n\n// send the file\ntry {\n    $s-\u003esend($file);\n} catch (\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n\n// but check the headers if it is not\n// working as expected as the guessing\n// of content-type does not always work\n// correctly. \n\n~~~\n\nWithout sending content-disposition header: \n\n~~~php\n\n// without sending content-disposition header\n// 2. param = false\ntry {\n    $s-\u003esend($file, false);\n} catch (\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n\n~~~\n\n# Test notes\n\nBuild image:\n\n    docker build -t php-apache2 .\n\nRun the docker image:\n\n    docker run -d -p 8080:80 -v $(pwd):/var/www/html --name test-send-file php-apache2\n\nEnable autoloading: \n\n    composer install\n\nGo to the browser at: http://localhost:8080/test\n\nOr use curl, e.g.: \n\n    curl -v -L -O -C - http://localhost:8080/test/send_large_file.php\n\n# Credits \n\nMuch of the code is taken (and rewritten) from here: \n\n\u003chttp://w-shadow.com/blog/2007/08/12/how-to-force-file-download-with-php/\u003e\n\nThe process is nicely explained here: \n\n\u003chttp://www.media-division.com/the-right-way-to-handle-file-downloads-in-php/\u003e\n\nMIT © [Dennis Iversen](https://github.com/diversen)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiversen%2Fhttp-send-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiversen%2Fhttp-send-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiversen%2Fhttp-send-file/lists"}