Created
November 6, 2010 01:43
-
-
Save kosso/665114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// perfect for using as an upload php script for the dnd-file-upload scripts by pangratz | |
// found at https://github.com/pangratz/dnd-file-upload | |
class File_Streamer{ | |
private $_fileName; | |
private $_contentLength; | |
private $_destination; | |
public function __construct(){ | |
if (!isset($_SERVER['HTTP_X_FILE_NAME']) | |
&& !isset($_SERVER['CONTENT_LENGTH'])) { | |
throw new Exception("No headers found!"); | |
} | |
$this->_fileName = $_SERVER['HTTP_X_FILE_NAME']; | |
$this->_contentLength = $_SERVER['CONTENT_LENGTH']; | |
} | |
public function isValid(){ | |
if (($this->_contentLength > 0)) { | |
return true; | |
} | |
return false; | |
} | |
public function setDestination($destination){ | |
$this->_destination = $destination; | |
} | |
public function receive(){ | |
if (!$this->isValid()) { | |
throw new Exception('No file uploaded!'); | |
} | |
file_put_contents( | |
$this->_destination . $this->_fileName, | |
file_get_contents("php://input") | |
); | |
return true; | |
} | |
} | |
$destination_path = '/some/writable/path/'; | |
$ft = new File_Streamer(); | |
$ft->setDestination($destination_path); | |
$ft->receive(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx :-)