Server IP : 127.0.0.2 / Your IP : 3.134.118.113 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/guzzlehttp/guzzle/src/Post/ |
Upload File : |
<?php namespace GuzzleHttp\Post; use GuzzleHttp\Mimetypes; use GuzzleHttp\Stream\StreamInterface; use GuzzleHttp\Stream\Stream; /** * Post file upload */ class PostFile implements PostFileInterface { private $name; private $filename; private $content; private $headers = []; /** * @param string $name Name of the form field * @param mixed $content Data to send * @param string|null $filename Filename content-disposition attribute * @param array $headers Array of headers to set on the file * (can override any default headers) * @throws \RuntimeException when filename is not passed or can't be determined */ public function __construct( $name, $content, $filename = null, array $headers = [] ) { $this->headers = $headers; $this->name = $name; $this->prepareContent($content); $this->prepareFilename($filename); $this->prepareDefaultHeaders(); } public function getName() { return $this->name; } public function getFilename() { return $this->filename; } public function getContent() { return $this->content; } public function getHeaders() { return $this->headers; } /** * Prepares the contents of a POST file. * * @param mixed $content Content of the POST file */ private function prepareContent($content) { $this->content = $content; if (!($this->content instanceof StreamInterface)) { $this->content = Stream::factory($this->content); } elseif ($this->content instanceof MultipartBody) { if (!$this->hasHeader('Content-Disposition')) { $disposition = 'form-data; name="' . $this->name .'"'; $this->headers['Content-Disposition'] = $disposition; } if (!$this->hasHeader('Content-Type')) { $this->headers['Content-Type'] = sprintf( "multipart/form-data; boundary=%s", $this->content->getBoundary() ); } } } /** * Applies a file name to the POST file based on various checks. * * @param string|null $filename Filename to apply (or null to guess) */ private function prepareFilename($filename) { $this->filename = $filename; if (!$this->filename) { $this->filename = $this->content->getMetadata('uri'); } if (!$this->filename || substr($this->filename, 0, 6) === 'php://') { $this->filename = $this->name; } } /** * Applies default Content-Disposition and Content-Type headers if needed. */ private function prepareDefaultHeaders() { // Set a default content-disposition header if one was no provided if (!$this->hasHeader('Content-Disposition')) { $this->headers['Content-Disposition'] = sprintf( 'form-data; name="%s"; filename="%s"', $this->name, basename($this->filename) ); } // Set a default Content-Type if one was not supplied if (!$this->hasHeader('Content-Type')) { $this->headers['Content-Type'] = Mimetypes::getInstance() ->fromFilename($this->filename) ?: 'text/plain'; } } /** * Check if a specific header exists on the POST file by name. * * @param string $name Case-insensitive header to check * * @return bool */ private function hasHeader($name) { return isset(array_change_key_case($this->headers)[strtolower($name)]); } }