Skip to content

Instantly share code, notes, and snippets.

@kosso
Created November 6, 2010 01:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosso/665114 to your computer and use it in GitHub Desktop.
Save kosso/665114 to your computer and use it in GitHub Desktop.
<?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();
?>
@christianhaller
Copy link

thx :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment