Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
I had a hard time to get github to merge the file (probably because I am not too familiar with merging branches, and my powershell keeps on erroring on me).

But this is merging the current php file with <a href="https://github.com/valums/file-uploader/pull/522">#522</a> and <a href="https://github.com/valums/file-uploader/pull/523">#523</a>
  • Loading branch information
KJLJon committed Dec 13, 2012
1 parent bb4b4d2 commit b7e2649
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions server/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
$allowedExtensions = array();
// max file size in bytes
$sizeLimit = 10 * 1024 * 1024;
//the input name set in the javascript
$inputName = 'qqfile'
require('valums-file-uploader/server/php.php');
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit, $inputName);
// Call handleUpload() with the name of the folder, relative to PHP's getcwd()
$result = $uploader->handleUpload('uploads/');
// to pass data through iframe you will need to encode all html tags
header("Content-Type: text/plain");
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
/******************************************/
Expand All @@ -26,6 +29,15 @@
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {
private $inputName;

/**
* @param string $inputName; defaults to the javascript default: 'qqfile'
*/
public function __construct($inputName = 'qqfile'){
$this->inputName = $inputName;
}

/**
* Save the file to the specified path
* @return boolean TRUE on success
Expand Down Expand Up @@ -53,7 +65,7 @@ public function save($path) {
* @return string filename
*/
public function getName() {
return $_GET['qqfile'];
return $_GET[$this->inputName];
}

/**
Expand All @@ -73,29 +85,37 @@ public function getSize() {
* Handle file uploads via regular form post (uses the $_FILES array)
*/
class qqUploadedFileForm {

private $inputName;

/**
* @param string $inputName; defaults to the javascript default: 'qqfile'
*/
public function __construct($inputName = 'qqfile'){
$this->inputName = $inputName;
}

/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
public function save($path) {
return move_uploaded_file($_FILES['qqfile']['tmp_name'], $path);
return move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $path);
}

/**
* Get the original filename
* @return string filename
*/
public function getName() {
return $_FILES['qqfile']['name'];
return $_FILES[$this->inputName]['name'];
}

/**
* Get the file size
* @return integer file-size in byte
*/
public function getSize() {
return $_FILES['qqfile']['size'];
return $_FILES[$this->inputName]['size'];
}
}

Expand All @@ -111,8 +131,9 @@ class qqFileUploader {
/**
* @param array $allowedExtensions; defaults to an empty array
* @param int $sizeLimit; defaults to the server's upload_max_filesize setting
* @param string $inputName; defaults to the javascript default: 'qqfile'
*/
function __construct(array $allowedExtensions = null, $sizeLimit = null){
function __construct(array $allowedExtensions = null, $sizeLimit = null, $inputName = 'qqfile'){
if($allowedExtensions===null) {
$allowedExtensions = array();
}
Expand All @@ -130,9 +151,9 @@ function __construct(array $allowedExtensions = null, $sizeLimit = null){
if(!isset($_SERVER['CONTENT_TYPE'])) {
$this->file = false;
} else if (strpos(strtolower($_SERVER['CONTENT_TYPE']), 'multipart/') === 0) {
$this->file = new qqUploadedFileForm();
$this->file = new qqUploadedFileForm($inputName);
} else {
$this->file = new qqUploadedFileXhr();
$this->file = new qqUploadedFileXhr($inputName);
}
}

Expand Down Expand Up @@ -237,4 +258,4 @@ function handleUpload($uploadDirectory, $replaceOldFile = FALSE){
}

}
}
}

0 comments on commit b7e2649

Please sign in to comment.