1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-24 15:23:11 +02:00

Bump version to 3.0.47, fix issue #139, issue #123, and issue #115

This commit is contained in:
Ryan Cramer
2016-12-30 13:09:07 -05:00
parent 8cb944cf52
commit 51bda526eb
9 changed files with 66 additions and 27 deletions

View File

@@ -240,6 +240,40 @@ class WireUpload extends Wire {
return $_FILES[$this->name];
}
/**
* Get the directory where files should upload to
*
* @return string
* @throws WireException If no suitable upload directory can be found
*
*/
protected function getUploadDir() {
$config = $this->wire('config');
$dir = $config->uploadTmpDir;
if(!$dir && stripos(PHP_OS, 'WIN') === 0) {
$dir = $config->paths->cache . 'uploads/';
if(!is_dir($dir)) wireMkdir($dir);
}
if(!$dir || !is_writable($dir)) {
$dir = ini_get('upload_tmp_dir');
}
if(!$dir || !is_writable($dir)) {
$dir = sys_get_temp_dir();
}
if(!$dir || !is_writable($dir)) {
throw new WireException(
"Error writing to $dir. Please define \$config->uploadTmpDir and ensure it exists and is writable."
);
}
return $dir;
}
/**
* Handles an ajax file upload and constructs a resulting $_FILES
*
@@ -251,13 +285,7 @@ class WireUpload extends Wire {
if(!$filename = $_SERVER['HTTP_X_FILENAME']) return false;
$filename = rawurldecode($filename); // per #1487
$dir = $this->wire('config')->uploadTmpDir;
if(!$dir || !is_writable($dir)) $dir = ini_get('upload_tmp_dir');
if(!$dir || !is_writable($dir)) $dir = sys_get_temp_dir();
if(!$dir || !is_writable($dir)) {
throw new WireException("Error writing to $dir. Please define \$config->uploadTmpDir and ensure it is writable.");
}
$dir = $this->getUploadDir();
$tmpName = tempnam($dir, wireClassName($this, false));
file_put_contents($tmpName, file_get_contents('php://input'));
$filesize = is_file($tmpName) ? filesize($tmpName) : 0;