Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Added composer support and added namespace usage
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox committed Jan 21, 2014
1 parent 2f0fc4b commit 62e7a1a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ This class is for providing downloads of files out of PHP, for example if you wa

# Usage

The examples assume, that you have included the namespace:
```php
use Apfelbox\FileDownload\FileDownload;
```


## Create a download for a file on your file system
```php
Expand Down
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "apfelbox/php-file-download",
"type": "library",
"description": "A library to help with creating downloads for files in PHP",
"keywords": ["download"],
"homepage": "https://github.com/apfelbox/PHP-File-Download",
"license": "MIT",
"authors": [
{
"name": "Jannik Zschiesche",
"email": "hello@apfelbox.net",
"homepage": "http://apfelbox.net"
}
],
"require": {
"php": ">=5.3",
"skyzyx/mimetypes": "~1.1"
},
"autoload": {
"psr-4": {
"Apfelbox\\FileDownload\\": "src/"
}
}
}
26 changes: 10 additions & 16 deletions FileDownload.php → src/FileDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* @license MIT
*/

namespace Apfelbox\FileDownload;

use Skyzyx\Components\Mimetypes\Mimetypes;

/**
* Provides a simple way to create file downloads in PHP
Expand All @@ -27,13 +30,13 @@ class FileDownload
*
* @param resource $filePointer
*
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function __construct ($filePointer)
{
if (!is_resource($filePointer))
{
throw new InvalidArgumentException("You must pass a file pointer to the ctor");
throw new \InvalidArgumentException("You must pass a file pointer to the ctor");
}

$this->filePointer = $filePointer;
Expand Down Expand Up @@ -81,20 +84,11 @@ public function sendDownload ($filename)
*/
private function getMimeType ($fileName)
{
switch (pathinfo($fileName, PATHINFO_EXTENSION))
{
case "pdf": return "application/pdf";
case "exe": return "application/octet-stream";
case "zip": return "application/zip";
case "doc": return "application/msword";
case "xls": return "application/vnd.ms-excel";
case "ppt": return "application/vnd.ms-powerpoint";
case "gif": return "image/gif";
case "png": return "image/png";
case "jpeg":
case "jpg": return "image/jpg";
default: return "application/force-download";
}
$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
$mimeTypeHelper = Mimetypes::getInstance();
$mimeType = $mimeTypeHelper->fromExtension($fileExtension);

return !is_null($mimeType) ? $mimeType : "application/force-download";
}


Expand Down

0 comments on commit 62e7a1a

Please sign in to comment.