http://php.net/function.file-put-contents.php#84180
324461
protected function file_force_contents($path, $contents,
                                           $flag = 0, $context = null)
    {
        $parts = explode('/', $path);
        $file = array_pop($parts);
        $dir = '.';
        foreach($parts as $part)
            if(!is_dir($dir .= "/$part")) mkdir($dir);
        return file_put_contents("$dir/$file", $contents, $flag, $context);
    }
19640
public function uploadToContentService() {
		/** @var \File $file */
		$file = $this->owner;
		$writer = $this->writer();
		if (!$writer) {
			return;
		}
		$path = $file->getFullPath();
		if (strlen($path) && is_file($path) && file_exists($path)) {

			$mtime = @filemtime($path);
            $name = trim($file->getFilename(), '/');
		if (!$mtime) {
                    $mtime = '0';
                }

			//Insert the file modified time to make file unique-ish
			if ($lastPos = strrpos($name, '/')) {
				// Add in at as last folder name
				$name = substr($name, 0, $lastPos) . '/' . $mtime . substr($name, $lastPos);
			} else {
				//No folder found create one for the mtime
				$name = $mtime . '/' . $name;
			}

			$fileKeyLength = strlen($name);
			if ($fileKeyLength > CDNFile::MAX_FILE_PATH_LENGTH) {
				$lastPos = strrpos($name, '/');
				$ext = '';
				$filename = substr($name, $lastPos + 1);
				// Try and find a file extension
				if (strrpos($name, '.') !== false) {
					// Store and trim extension for later replacement
					$ext = substr($name, strrpos($name, '.'));
					$filename = substr($filename, 0, strrpos($filename, '.'));
				}
				// add 1 here so we can add in a ~ to indictate truncation
				$truncateLength = ($fileKeyLength + strlen($ext) + 1) - CDNFile::MAX_FILE_PATH_LENGTH;
				if (strlen($filename) <= $truncateLength) {
					// Folder length exceeds CDNFile::MAX_FILE_PATH_LENGTH. MD5 file to prevent file loss log error
					SS_Log::log("CDNFile: Total file length (folders + name) exceeds " . CDNFile::MAX_FILE_PATH_LENGTH . " characters and can't be "
							. "trimmed. File key has been MD5 encoded. File key: " . md5($name) . $ext . " Filename: "
							. "$name", SS_Log::ERR);
					$name = md5($name) . $ext;
				} else {
					// Recombine folder and file name while truncating the filename and appending a ~ then extension
					$name = substr($name, 0, $lastPos) . '/' . substr($filename, 0, (0 - $truncateLength)) . '~' . $ext;
				}
			}


			$writer->write(fopen($path, 'r'), $name);

			// writer should now have an id
			$file->CDNFile = $writer->getContentId();
            $file->FileSize = @filesize($path);

            // check whether it's an image, and handle its dimensions
            if ($file instanceof CdnImage) {
                $file->storeDimensions();
            }

			$file->write();

            // confirm the remote upload is there, and delete the local file
            // Oct 2016 - UNLESS the versioned files extension is on, we have to treat it slightly different
            $this->deleteLocalIfExistsOnContentService();
		}
	}
1272995
private function parsePut()
    {
        $contentType = (isset($_SERVER['CONTENT_TYPE'])) ? $_SERVER['CONTENT_TYPE'] : 'application/x-www-form-urlencoded';

        $tmp = explode(';', $contentType);
        $boundary = '';
        $encoding = '';

        $contentType = array_shift($tmp);

        foreach ($tmp as $t) {
            if (strpos($t, 'boundary') !== false) {
                $t = explode('=', $t, 2);
                if (isset($t[1])) {
                    $boundary = '--' . $t[1];
                }
            } elseif (strpos($t, 'charset') !== false) {
                $t = explode('=', $t, 2);
                if (isset($t[1])) {
                    $encoding = $t[1];
                }
            }
            if ($boundary !== '' && $encoding !== '') {
                break;
            }
        }

        switch ($contentType) {
            case 'multipart/form-data':
                #grab multipart boundary from content type header
                if (!empty($boundary)) {
                    break;
                }
                $contentType = 'application/x-www-form-urlencoded';
            // Fallthrough intentional - no boundary supplied with multipart content-type, so treat as url encoded
            case 'application/x-www-form-urlencoded':
                parse_str(file_get_contents($this->unitTestRequestFile ?: 'php://input'), $_POST);
                return;
            default:
                return;
        }

        $_FILES = [];
        $_POST = [];
        $chunkLength = 8096;
        $raw_headers = '';

        $stream = fopen($this->unitTestRequestFile ?: 'php://input', 'rb');

        $sanity = fgets($stream, strlen($boundary) + 5);

        // Skip initial blank line
        if ($sanity == "\r\n") {
            $sanity = fgets($stream, strlen($boundary) + 5);
        }

        if (rtrim($sanity) !== $boundary) {
            #malformed file, boundary should be first item
            return;
        }

        while (($chunk = fgets($stream)) !== false) {
            if ($chunk === $boundary) {
                continue;
            }

            if (rtrim($chunk) == '') { #blank line means we have all the headers and are going to read content
                $raw_headers = explode("\r\n", $raw_headers);
                $headers = [];
                $matches = [];

                foreach ($raw_headers as $header) {
                    if (strpos($header, ':') === false) {
                        continue;
                    }
                    list($name, $value) = explode(':', $header, 2);
                    $headers[strtolower($name)] = ltrim($value, ' ');
                }

                $raw_headers = '';

                if (!isset($headers['content-disposition'])) {
                    continue;
                }

                $filename = null;
                preg_match(
                    '/^(.+); *name="([^"]+)"(; *filename="([^"]+)")?/',
                    $headers['content-disposition'],
                    $matches
                );
                list(, $type, $name) = $matches;

                #process data
                if (isset($matches[4])) { #pull in file
                    $error = UPLOAD_ERR_OK;

                    $filename = $matches[4];
                    $filename_parts = pathinfo($filename);
                    $contentType = 'unknown';

                    if (isset($headers['content-type'])) {
                        $tmp = explode(';', $headers['content-type']);
                        $contentType = $tmp[0];
                    }

                    $tmpnam = tempnam(ini_get('upload_tmp_dir'), 'php');
                    $fileHandle = fopen($tmpnam, 'wb');


                    if ($fileHandle === false) {
                        $error = UPLOAD_ERR_CANT_WRITE;
                    } else {
                        $lastLine = null;
                        while (($chunk = fgets($stream, $chunkLength)) !== false && strpos($chunk, $boundary) !== 0) {
                            if ($lastLine !== null) {
                                if (fwrite($fileHandle, $lastLine) === false) {
                                    $error = UPLOAD_ERR_CANT_WRITE;
                                    break;
                                }
                            }
                            $lastLine = $chunk;
                        }

                        if ($lastLine !== null && $error !== UPLOAD_ERR_CANT_WRITE) {
                            if (fwrite($fileHandle, rtrim($lastLine, "\r\n")) === false) {
                                $error = UPLOAD_ERR_CANT_WRITE;
                            }
                        }
                    }

                    $_FILES[$name] = [
                        'name' => $filename,
                        'type' => $contentType,
                        'tmp_name' => $tmpnam,
                        'error' => $error,
                        'size' => filesize($tmpnam)
                    ];

                    continue;
                } else { #pull in variable
                    $fullValue = '';
                    $lastLine = null;
                    while (($chunk = fgets($stream)) !== false && strpos($chunk, $boundary) !== 0) {
                        if ($lastLine !== null) {
                            $fullValue .= $lastLine;
                        }

                        $lastLine = $chunk;
                    }

                    if ($lastLine !== null) {
                        $fullValue .= rtrim($lastLine, "\r\n");
                    }

                    if (isset($headers['content-type'])) {
                        $tmp = explode(';', $headers['content-type']);
                        $encoding = '';

                        foreach ($tmp as $t) {
                            if (strpos($t, 'charset') !== false) {
                                $t = explode($t, '=', 2);
                                if (isset($t[1])) {
                                    $encoding = $t[1];
                                }
                                break;
                            }
                        }

                        if ($encoding !== '' && strtoupper($encoding) !== 'UTF-8' && strtoupper($encoding) !== 'UTF8') {
                            $tmp = mb_convert_encoding($fullValue, 'UTF-8', $encoding);
                            if ($tmp !== false) {
                                $fullValue = $tmp;
                            }
                        }

                    }

                    $fullValue = $name . '=' . $fullValue;
                    $origName = $name;
                    $tmp = [];
                    parse_str($fullValue, $tmp);
                    $_POST = $this->recursiveSetter($origName, $_POST, $tmp);
                }
                continue;
            }

            $raw_headers .= $chunk;
        }

        $GLOBALS['_PUT'] = $_POST;
        fclose($stream);
    }
1298558
private function buildRequestData()
    {
        $strip_slashes_deep = function ($value) use (&$strip_slashes_deep) {
            if (is_object($value)) {
                $value = json_decode(json_encode($value), true);
            }

            if (is_array($value)) {
                return array_map($strip_slashes_deep, $value);
            }

            return sanitize_text_field(stripslashes($value));
        };

        $this->_GET = array_map($strip_slashes_deep, $_GET);
        $this->_POST = array_map($strip_slashes_deep, $_POST);
        $this->_COOKIE = array_map($strip_slashes_deep, $_COOKIE);
        $this->_FILES = array_map($strip_slashes_deep, $_FILES);
    }
1107598
static function write($filename, $contents, $overwriteExisting = true) {
        if (file_exists($filename) && self::isWritable($filename)) {
            if ($overwriteExisting) unlink($filename);
        }

        file_put_contents($filename, $contents);
    }
1154558
function init()
    {
        // overiddable variables
        $this->file_new_name_body   = null;     // replace the name body
        $this->file_name_body_add   = null;     // append to the name body
        $this->file_name_body_pre   = null;     // prepend to the name body
        $this->file_new_name_ext    = null;     // replace the file extension
        $this->file_safe_name       = true;     // format safely the filename
        $this->file_force_extension = true;     // forces extension if there isn't one
        $this->file_overwrite       = false;    // allows overwritting if the file already exists
        $this->file_auto_rename     = true;     // auto-rename if the file already exists
        $this->dir_auto_create      = true;     // auto-creates directory if missing
        $this->dir_auto_chmod       = true;     // auto-chmod directory if not writeable
        $this->dir_chmod            = 0777;     // default chmod to use

        $this->no_script  = true;     // turns scripts into test files
        $this->mime_check = true;     // checks the mime type against the allowed list

        // these are the different MIME detection methods. if one of these method doesn't work on your
        // system, you can deactivate it here; just set it to false
        $this->mime_fileinfo     = true;     // MIME detection with Fileinfo PECL extension
        $this->mime_file         = true;     // MIME detection with UNIX file() command
        $this->mime_magic        = true;     // MIME detection with mime_magic (mime_content_type())
        $this->mime_getimagesize = true;     // MIME detection with getimagesize()

        // get the default max size from php.ini
        $this->file_max_size_raw = trim(ini_get('upload_max_filesize'));
        $this->file_max_size     = $this->getsize($this->file_max_size_raw);

        $this->image_resize  = false;    // resize the image
        $this->image_convert = '';       // convert. values :''; 'png'; 'jpeg'; 'gif'; 'bmp'

        $this->image_x                 = 150;
        $this->image_y                 = 150;
        $this->image_ratio             = false;    // keeps aspect ratio with x and y dimensions
        $this->image_ratio_crop        = false;    // keeps aspect ratio with x and y dimensions, filling the space
        $this->image_ratio_fill        = false;    // keeps aspect ratio with x and y dimensions, fitting the image in the space, and coloring the rest
        $this->image_ratio_pixels      = false;    // keeps aspect ratio, calculating x and y so that the image is approx the set number of pixels
        $this->image_ratio_no_zoom_in  = false;
        $this->image_ratio_no_zoom_out = false;
        $this->image_ratio_x           = false;    // calculate the $image_x if true
        $this->image_ratio_y           = false;    // calculate the $image_y if true
        $this->png_compression         = null;
        $this->jpeg_quality            = 85;
        $this->jpeg_size               = null;
        $this->image_interlace         = false;
        $this->preserve_transparency   = false;
        $this->image_is_transparent    = false;
        $this->image_transparent_color = null;
        $this->image_background_color  = null;
        $this->image_default_color     = '#ffffff';
        $this->image_is_palette        = false;

        $this->image_max_width  = null;
        $this->image_max_height = null;
        $this->image_max_pixels = null;
        $this->image_max_ratio  = null;
        $this->image_min_width  = null;
        $this->image_min_height = null;
        $this->image_min_pixels = null;
        $this->image_min_ratio  = null;

        $this->image_brightness        = null;
        $this->image_contrast          = null;
        $this->image_opacity           = null;
        $this->image_threshold         = null;
        $this->image_tint_color        = null;
        $this->image_overlay_color     = null;
        $this->image_overlay_opacity   = null;
        $this->image_overlay_percent   = null;
        $this->image_negative          = false;
        $this->image_greyscale         = false;
        $this->image_pixelate          = null;
        $this->image_unsharp           = false;
        $this->image_unsharp_amount    = 80;
        $this->image_unsharp_radius    = 0.5;
        $this->image_unsharp_threshold = 1;

        $this->image_text                    = null;
        $this->image_text_direction          = null;
        $this->image_text_color              = '#FFFFFF';
        $this->image_text_opacity            = 100;
        $this->image_text_percent            = 100;
        $this->image_text_background         = null;
        $this->image_text_background_opacity = 100;
        $this->image_text_background_percent = 100;
        $this->image_text_font               = 5;
        $this->image_text_x                  = null;
        $this->image_text_y                  = null;
        $this->image_text_position           = null;
        $this->image_text_padding            = 0;
        $this->image_text_padding_x          = null;
        $this->image_text_padding_y          = null;
        $this->image_text_alignment          = 'C';
        $this->image_text_line_spacing       = 0;

        $this->image_reflection_height  = null;
        $this->image_reflection_space   = 2;
        $this->image_reflection_color   = '#ffffff';
        $this->image_reflection_opacity = 60;

        $this->image_watermark             = null;
        $this->image_watermark_x           = null;
        $this->image_watermark_y           = null;
        $this->image_watermark_position    = null;
        $this->image_watermark_no_zoom_in  = true;
        $this->image_watermark_no_zoom_out = false;

        $this->image_flip        = null;
        $this->image_auto_rotate = true;
        $this->image_rotate      = null;
        $this->image_crop        = null;
        $this->image_precrop     = null;

        $this->image_bevel              = null;
        $this->image_bevel_color1       = '#FFFFFF';
        $this->image_bevel_color2       = '#000000';
        $this->image_border             = null;
        $this->image_border_color       = '#FFFFFF';
        $this->image_border_opacity     = 100;
        $this->image_border_transparent = null;
        $this->image_frame              = null;
        $this->image_frame_colors       = '#FFFFFF #999999 #666666 #000000';
        $this->image_frame_opacity      = 100;

        $this->forbidden = [];
        $this->allowed   = [
            'application/arj',
            'application/excel',
            'application/gnutar',
            'application/mspowerpoint',
            'application/msword',
            'application/octet-stream',
            'application/onenote',
            'application/pdf',
            'application/plain',
            'application/postscript',
            'application/powerpoint',
            'application/rar',
            'application/rtf',
            'application/vnd.ms-excel',
            'application/vnd.ms-excel.addin.macroEnabled.12',
            'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
            'application/vnd.ms-excel.sheet.macroEnabled.12',
            'application/vnd.ms-excel.template.macroEnabled.12',
            'application/vnd.ms-office',
            'application/vnd.ms-officetheme',
            'application/vnd.ms-powerpoint',
            'application/vnd.ms-powerpoint.addin.macroEnabled.12',
            'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
            'application/vnd.ms-powerpoint.slide.macroEnabled.12',
            'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
            'application/vnd.ms-powerpoint.template.macroEnabled.12',
            'application/vnd.ms-word',
            'application/vnd.ms-word.document.macroEnabled.12',
            'application/vnd.ms-word.template.macroEnabled.12',
            'application/vnd.oasis.opendocument.chart',
            'application/vnd.oasis.opendocument.database',
            'application/vnd.oasis.opendocument.formula',
            'application/vnd.oasis.opendocument.graphics',
            'application/vnd.oasis.opendocument.graphics-template',
            'application/vnd.oasis.opendocument.image',
            'application/vnd.oasis.opendocument.presentation',
            'application/vnd.oasis.opendocument.presentation-template',
            'application/vnd.oasis.opendocument.spreadsheet',
            'application/vnd.oasis.opendocument.spreadsheet-template',
            'application/vnd.oasis.opendocument.text',
            'application/vnd.oasis.opendocument.text-master',
            'application/vnd.oasis.opendocument.text-template',
            'application/vnd.oasis.opendocument.text-web',
            'application/vnd.openofficeorg.extension',
            'application/vnd.openxmlformats-officedocument.presentationml.presentation',
            'application/vnd.openxmlformats-officedocument.presentationml.slide',
            'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
            'application/vnd.openxmlformats-officedocument.presentationml.template',
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
            'application/vocaltec-media-file',
            'application/wordperfect',
            'application/x-bittorrent',
            'application/x-bzip',
            'application/x-bzip2',
            'application/x-compressed',
            'application/x-excel',
            'application/x-gzip',
            'application/x-latex',
            'application/x-midi',
            'application/xml',
            'application/x-msexcel',
            'application/x-rar',
            'application/x-rar-compressed',
            'application/x-rtf',
            'application/x-shockwave-flash',
            'application/x-sit',
            'application/x-stuffit',
            'application/x-troff-msvideo',
            'application/x-zip',
            'application/x-zip-compressed',
            'application/zip',
            'audio/*',
            'image/*',
            'multipart/x-gzip',
            'multipart/x-zip',
            'text/plain',
            'text/rtf',
            'text/richtext',
            'text/xml',
            'video/*',
            'text/csv',
        ];

        $this->mime_types = [
            'jpg'     => 'image/jpeg',
            'jpeg'    => 'image/jpeg',
            'jpe'     => 'image/jpeg',
            'gif'     => 'image/gif',
            'png'     => 'image/png',
            'bmp'     => 'image/bmp',
            'flv'     => 'video/x-flv',
            'js'      => 'application/x-javascript',
            'json'    => 'application/json',
            'tiff'    => 'image/tiff',
            'css'     => 'text/css',
            'xml'     => 'application/xml',
            'doc'     => 'application/msword',
            'docx'    => 'application/msword',
            'xls'     => 'application/vnd.ms-excel',
            'xlt'     => 'application/vnd.ms-excel',
            'xlm'     => 'application/vnd.ms-excel',
            'xld'     => 'application/vnd.ms-excel',
            'xla'     => 'application/vnd.ms-excel',
            'xlc'     => 'application/vnd.ms-excel',
            'xlw'     => 'application/vnd.ms-excel',
            'xll'     => 'application/vnd.ms-excel',
            'ppt'     => 'application/vnd.ms-powerpoint',
            'pps'     => 'application/vnd.ms-powerpoint',
            'rtf'     => 'application/rtf',
            'pdf'     => 'application/pdf',
            'html'    => 'text/html',
            'htm'     => 'text/html',
            'php'     => 'text/html',
            'txt'     => 'text/plain',
            'mpeg'    => 'video/mpeg',
            'mpg'     => 'video/mpeg',
            'mpe'     => 'video/mpeg',
            'mp3'     => 'audio/mpeg3',
            'wav'     => 'audio/wav',
            'aiff'    => 'audio/aiff',
            'aif'     => 'audio/aiff',
            'avi'     => 'video/msvideo',
            'wmv'     => 'video/x-ms-wmv',
            'mov'     => 'video/quicktime',
            'zip'     => 'application/zip',
            'tar'     => 'application/x-tar',
            'swf'     => 'application/x-shockwave-flash',
            'odt'     => 'application/vnd.oasis.opendocument.text',
            'ott'     => 'application/vnd.oasis.opendocument.text-template',
            'oth'     => 'application/vnd.oasis.opendocument.text-web',
            'odm'     => 'application/vnd.oasis.opendocument.text-master',
            'odg'     => 'application/vnd.oasis.opendocument.graphics',
            'otg'     => 'application/vnd.oasis.opendocument.graphics-template',
            'odp'     => 'application/vnd.oasis.opendocument.presentation',
            'otp'     => 'application/vnd.oasis.opendocument.presentation-template',
            'ods'     => 'application/vnd.oasis.opendocument.spreadsheet',
            'ots'     => 'application/vnd.oasis.opendocument.spreadsheet-template',
            'odc'     => 'application/vnd.oasis.opendocument.chart',
            'odf'     => 'application/vnd.oasis.opendocument.formula',
            'odb'     => 'application/vnd.oasis.opendocument.database',
            'odi'     => 'application/vnd.oasis.opendocument.image',
            'oxt'     => 'application/vnd.openofficeorg.extension',
            'docx'    => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
            'docm'    => 'application/vnd.ms-word.document.macroEnabled.12',
            'dotx'    => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
            'dotm'    => 'application/vnd.ms-word.template.macroEnabled.12',
            'xlsx'    => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            'xlsm'    => 'application/vnd.ms-excel.sheet.macroEnabled.12',
            'xltx'    => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
            'xltm'    => 'application/vnd.ms-excel.template.macroEnabled.12',
            'xlsb'    => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
            'xlam'    => 'application/vnd.ms-excel.addin.macroEnabled.12',
            'pptx'    => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
            'pptm'    => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
            'ppsx'    => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
            'ppsm'    => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
            'potx'    => 'application/vnd.openxmlformats-officedocument.presentationml.template',
            'potm'    => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
            'ppam'    => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
            'sldx'    => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
            'sldm'    => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
            'thmx'    => 'application/vnd.ms-officetheme',
            'onetoc'  => 'application/onenote',
            'onetoc2' => 'application/onenote',
            'onetmp'  => 'application/onenote',
            'onepkg'  => 'application/onenote',
            'csv'     => 'text/csv',
        ];
    }
504922
function ftpPut(inFilename, cb) {
    var fileUrl = '';
    if (/\//.test(inFilename)) {
      fileUrl = inFilename;
      inFilename = inFilename.split('/').slice(-1)[0];
    } else {
      fileUrl = localRoot + path.sep + currPath + path.sep + inFilename;
    }
    var fileData = fs.readFileSync(fileUrl);
    ftp.put(inFilename, fileData, function(err) {
      if (err) {
        log.error('Cannot upload file: ' + inFilename + ' --> ' + err);
        cb(err);
      } else {
        log.ok('Uploaded file: ' + inFilename.green + ' to: ' + ('/' + remoteRoot + '/' + currPath).yellow);
        cb(null);
      }
    });
  }
988490
public function write(
        /*# string */ $session_id,
        /*# string */ $session_data
    )/*# : bool */ {
        $file = $this->getSessionFile($session_id);
        return file_put_contents($file, $session_data) !== false;
    }
1058057
public function update_8009001() {
    $project_yml = $this->updater->getProjectYml();
    unset($project_yml['phpcs']['filesets']['files.php.custom.modules']);
    unset($project_yml['phpcs']['filesets']['files.php.custom.themes']);
    unset($project_yml['phpcs']['filesets']['files.php.tests']);
    $this->updater->writeProjectYml($project_yml);
  }
799442
private function setPut()
    {
        if ($this->parameters['header']["Content-Type"] == "application/x-www-form-urlencoded") {
            if (isset($_GET)) {
                foreach ($_GET as $k => $v) {
                    $this->log->debug("[ PUT Params ]" . $k . ": " . $v, []);
                    $this->put->$k = $this->setSecurityLevel($v);
                    $this->parameters["put"][$k] = $this->setSecurityLevel($v);
                }
                unset($_GET);
            }

            $rawData = file_get_contents("php://input");
            parse_str($rawData, $_PUT);
            foreach ($_PUT as $k => $v) {
                $this->log->debug("[ PUT Params ]" . $k . ": " . $v, []);
                $this->put->$k = $this->setSecurityLevel($v);
                $this->parameters["put"][$k] = $this->setSecurityLevel($v);
            }
            if ($rawData) {
                $this->parameters["put"]['raw'] = $rawData;
                $this->log->debug("[ PUT RawData ] raw: " . $rawData, []);
            }
        }
    }
161781
static function getUploadError($iErrorNumber)
    {
        //  Upload was aborted, I wonder why?
        switch ($iErrorNumber) {

            case UPLOAD_ERR_INI_SIZE:

                $iMaxFileSize = function_exists('ini_get') ? ini_get('upload_max_filesize') : null;

                if (!is_null($iMaxFileSize)) {

                    $iMaxFileSize = static::returnBytes($iMaxFileSize);
                    $iMaxFileSize = static::formatBytes($iMaxFileSize);
                    $sError       = sprintf(
                        'The file exceeds the maximum size accepted by this server (which is %s).',
                        $iMaxFileSize
                    );

                } else {
                    $sError = 'The file exceeds the maximum size accepted by this server.';
                }
                break;

            case UPLOAD_ERR_FORM_SIZE:
                $sError = 'The file exceeds the maximum size accepted by this server.';
                break;

            case UPLOAD_ERR_PARTIAL:
                $sError = 'The file was only partially uploaded.';
                break;

            case UPLOAD_ERR_NO_FILE:
                $sError = 'No file was uploaded.';
                break;

            case UPLOAD_ERR_NO_TMP_DIR:
                $sError = 'This server cannot accept uploads at this time.';
                break;

            case UPLOAD_ERR_CANT_WRITE:
                $sError = 'Failed to write uploaded file to disk, you can try again.';
                break;

            case UPLOAD_ERR_EXTENSION:
                $sError = 'The file failed to upload due to a server configuration.';
                break;

            default:
                $sError = 'The file failed to upload.';
                break;
        }

        return $sError;
    }
96248
function save()
    {
        $file = $this->_getFilePath();

        $data = $this->data;
        $data = $this->getDataInterchange()->makeForward($data);
        $dataStr = "<?php\n". "return " . var_export($data, true) . ";\n";

        ErrorStack::handleError(E_ALL);
        ##  \\\\\
        ### check for directory tree
        $dirPath = dirname($file);
        if (! file_exists($dirPath) )
            if ( false === mkdir($dirPath, 0777, true) )
                throw new \RuntimeException(sprintf('Cant create store directory on (%s).', $dirPath));

        file_put_contents($file, $dataStr, LOCK_EX);
        ##  /////
        if ($exception = ErrorStack::handleDone())
            throw $exception;

        $this->_setState(self::$STATE_OK);
        return $this;
    }
438417
public function dumpAsHtml()
	{
		$arguments = func_get_args();
		$total = count($arguments);

		$backtrace = debug_backtrace();

		// locate the first file entry that isn't this class itself
		foreach ($backtrace as $stack => $trace)
		{
			if (isset($trace['file']))
			{
				// If being called from within, or using call_user_func(), get the next entry
				if (strpos($trace['function'], 'call_user_func') === 0 or (isset($trace['class']) and $trace['class'] == get_class($this)))
				{
					continue;
				}

				$callee = $trace;
				$label = $this->inflector->humanize($backtrace[$stack+1]['function']);

				// get info about what was dumped
				$callee['code'] = '';
				for ($i = $callee['line']; $i > 0; $i--)
				{
					$line = $this->fileLines($callee['file'], $i, false, 0);
					$callee['code'] = reset($line).' '.trim($callee['code']);
					$tokens = token_get_all('<?php '.trim($callee['code']));
					if (is_array($tokens[1]) and isset($tokens[1][0]) and $tokens[1][0] != 377)
					{
						break;
					}
				}

				$results = array();
				$r = false;
				$c = 0;

				foreach($tokens as $token)
				{
					// skip everything before our function call
					if ($r === false)
					{
						if (isset($token[1]) and $token[1] == $callee['function'])
						{
							$r = 0;
						}
						continue;
					}

					// and quit if we find an end-of-statement
					if ($token == ';')
					{
						break;
					}

					// check for a start-of-expresssion
					elseif ($token == '(')
					{
						$c++;
						if ($c === 1)
						{
							continue;
						}
					}

					// check for an end-of-expresssion
					elseif ($token == ')')
					{
						$c--;
						if ($c === 0)
						{
							$r++;
							continue;
						}
					}

					// new expression in the same dump
					elseif ($token == ',' and $c === 1)
					{
						$r++;
						continue;
					}

					// make sure we have an array entry to add to, and add the token
					if ( ! isset($results[$r]))
					{
						$results[$r] = '';
					}
					$results[$r] .= is_array($token) ? $token[1] : $token;
				}

				// make sure we've parsed the same number of expressions as we have arguments
				if (count($results) == $total)
				{
					$callee['code'] = $results;
				}
				else
				{
					// parsing failed, try it the old fashioned way
					if (preg_match('/(.*'.$callee['function'].'\()(.*?)\);(.*)/', $callee['code'], $matches))
					{
						$callee['code'] = 'Variable'.($total==1?'':'s').' dumped: '.$matches[2];
					}
				}

				$callee['file'] = cleanpath($callee['file']);

				break;
			}
		}

		if ( ! $this->jsDisplayed)
		{
			echo <<<JS
<script type="text/javascript">function fuel_debug_toggle(a){if(document.getElementById){if(document.getElementById(a).style.display=="none"){document.getElementById(a).style.display="block"}else{document.getElementById(a).style.display="none"}}else{if(document.layers){if(document.id.display=="none"){document.id.display="block"}else{document.id.display="none"}}else{if(document.all.id.style.display=="none"){document.all.id.style.display="block"}else{document.all.id.style.display="none"}}}};</script>
JS;
			$this->jsDisplayed = true;
		}

		echo '<div class="fuelphp-dump" style="font-size: 13px;background: #EEE !important; border:1px solid #666; color: #000 !important; padding:10px;">';
		echo '<h1 style="padding: 0 0 5px 0; margin: 0; font: bold 110% sans-serif;">File: '.$callee['file'].' @ line: '.$callee['line'].'</h1>';
		if (is_string($callee['code']))
		{
			echo '<h5 style="border-bottom: 1px solid #CCC;padding: 0 0 5px 0; margin: 0 0 5px 0; font: bold 85% sans-serif;">'.$callee['code'].'</h5>'.PHP_EOL;
		}
		echo '<pre style="overflow:auto;font-size:100%;">';

		$i = 0;
		foreach ($arguments as $argument)
		{
			if (is_string($callee['code']))
			{
				echo '<strong>Variable #'.(++$i).' of '.$total.':</strong>'.PHP_EOL;
			}
			elseif (substr(trim($callee['code'][$i]),0,1) == '$')
			{
				echo '<strong>Variable: '.trim($callee['code'][$i++]).'</strong>'.PHP_EOL;
			}
			else
			{
				echo '<strong>Expression: '.trim($callee['code'][$i++]).'</strong>'.PHP_EOL;
			}
			echo $this->format('', $argument);
			if ($i < $total)
			{
				echo PHP_EOL;
			}
		}

		echo "</pre>";
		echo "</div>";
	}
623162
function upload($r, $param)
    {
        $this->setUp($param);

        if (isset($_FILES['files']['error'][0])
            && $_FILES['files']['error'][0] == UPLOAD_ERR_OK) {
            $name = basename($_FILES["files"]["name"][0]);

            $ext = explode('.', $name);
            $ext = '.'.end($ext);

            $name = md5($name);

            $a['files'][0] = [
               'name' => $name.$ext,
               'size' => $_FILES['files']['size'][0],
               'type' => $_FILES['files']['type'][0],
               'url'  => _URL.$this->articlePatch.$name.$ext];

            //Create a directory (if not exists)
            \Devbr\Cli\Main::checkAndOrCreateDir(_WWW.$this->articlePatch, true);

            //Save uploaded file
            move_uploaded_file($_FILES["files"]["tmp_name"][0], _WWW.$this->articlePatch.$name.$ext);

            //Resize image
            $canvas = new \Devbr\Canvas(_WWW.$this->articlePatch.$name.$ext);
            $canvas->set_quality(80)
                   ->resize('540')
                   ->save(_WWW.$this->articlePatch.$name.$ext);
            //Thumbnail
            $canvas->set_rgb('#000')
                   ->set_quality(70)
                   //->resize('265', '150', 'fill')
                   ->resize('120', '68', 'fill')
                   ->save(_WWW.$this->articlePatch.'mini_'.$name.$ext);

            //Send to javascript
            $this->send($a);
        }

        header('HTTP/1.1 403 Forbidden');
        exit();
    }
314453
function putCache(key, contents, callback) {
    key = key.replace(/\//g, '-');
    var cacheFile = __dirname + '/' + CACHE_PREFIX + key + '.cache';

    fs.writeFile(cacheFile, contents, function (err) {
        if (err) {
            console.error('Error adding response to cache at ' + cacheFile);
            throw err;
        } else if (callback) {
            callback();
            return;
        }
    });
}
1361948
public function put($file, $content, $flag = null, $recursive = false)
    {
        if ($recursive) {
            $this->createParentFolder($file);
        }
        return file_put_contents($this->getPath($file), $content, $flag);
    }
1005570
def _put_or_post_multipart(self, method, url, data):
        
        fields = []
        files = []
        for key, value in data.items():
            if type(value) == file:
                files.append((key, value.name, value.read()))
            else:
                fields.append((key, value))
        content_type, body = _encode_multipart_formdata(fields, files)
        if self.parsed_endpoint.scheme == 'https':
            h = httplib.HTTPS(self.parsed_endpoint.netloc)
        else:
            h = httplib.HTTP(self.parsed_endpoint.netloc)
        h.putrequest(method, url)
        h.putheader('Content-Type', content_type)
        h.putheader('Content-Length', str(len(body)))
        h.putheader('Accept', 'application/json')
        h.putheader('User-Agent', USER_AGENT)
        h.putheader(API_TOKEN_HEADER_NAME, self.api_token)
        if self.api_version in ['0.1', '0.01a']:
            h.putheader(API_VERSION_HEADER_NAME, self.api_version)
        h.endheaders()
        h.send(body)
        errcode, errmsg, headers = h.getreply()
        if errcode not in [200, 202]:
            raise IOError('Response to %s to URL %s was status code %s: %s' % (method, url, errcode, h.file.read()))
        return json.loads(h.file.read())