Example #1
3
/**
 * Submits an HTTP POST to a reCAPTCHA server
 * @param string $host
 * @param string $path
 * @param array $data
 * @param int port
 * @return array response
 */
function _recaptcha_http_post($host, $path, $data, $port = 80)
{
    $req = _recaptcha_qsencode($data);
    $proxy_host = "proxy.iiit.ac.in";
    $proxy_port = "8080";
    $http_request = "POST http://{$host}{$path} HTTP/1.0\r\n";
    $http_request .= "Host: {$host}\r\n";
    $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
    $http_request .= "Content-Length: " . strlen($req) . "\r\n";
    $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
    $http_request .= "\r\n";
    $http_request .= $req;
    $response = '';
    if (false == ($fs = @fsockopen($proxy_host, $proxy_port, $errno, $errstr, 10))) {
        die('Could not open socket aah');
    }
    fwrite($fs, $http_request);
    while (!feof($fs)) {
        $response .= fgets($fs, 1160);
    }
    // One TCP-IP packet
    fclose($fs);
    $response = explode("\r\n\r\n", $response, 2);
    return $response;
}
Example #2
2
 function generatePDF()
 {
     // tempfolder
     $tmpBaseFolder = TEMP_FOLDER . '/shopsystem';
     $tmpFolder = project() ? "{$tmpBaseFolder}/" . project() : "{$tmpBaseFolder}/site";
     if (is_dir($tmpFolder)) {
         Filesystem::removeFolder($tmpFolder);
     }
     if (!file_exists($tmpFolder)) {
         Filesystem::makeFolder($tmpFolder);
     }
     $baseFolderName = basename($tmpFolder);
     //Get site
     Requirements::clear();
     $link = Director::absoluteURL($this->pdfLink() . "/?view=1");
     $response = Director::test($link);
     $content = $response->getBody();
     $content = utf8_decode($content);
     $contentfile = "{$tmpFolder}/" . $this->PublicURL . ".html";
     if (!file_exists($contentfile)) {
         // Write to file
         if ($fh = fopen($contentfile, 'w')) {
             fwrite($fh, $content);
             fclose($fh);
         }
     }
     return $contentfile;
 }
Example #3
1
 public function testTooLargeMegaBytes()
 {
     fwrite($this->file, str_repeat('0', 1400000));
     $constraint = new File(array('maxSize' => '1M', 'maxSizeMessage' => 'myMessage'));
     $this->context->expects($this->once())->method('addViolation')->with('myMessage', array('{{ limit }}' => '1 MB', '{{ size }}' => '1.4 MB', '{{ file }}' => $this->path));
     $this->validator->validate($this->getFile($this->path), $constraint);
 }
function wsOnMessage($clientID, $message, $messageLength, $binary)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    // check if message length is 0
    if ($messageLength == 0) {
        $Server->wsClose($clientID);
        return;
    }
    //The speaker is the only person in the room. Don't let them feel lonely.
    if (sizeof($Server->wsClients) == 1) {
        $Server->wsSend($clientID, "There isn't anyone else in the room, but I'll still listen to you. --Your Trusty Server");
    } else {
        //Send the message to everyone but the person who said it
        foreach ($Server->wsClients as $id => $client) {
            if ($id != $clientID) {
                $Server->wsSend($id, "{$message}");
            }
        }
    }
    //and to arduino forst decoding mesage and sending only one byte
    if ("{$message}" == "arduino1") {
        `mode com4: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
        $fp = fopen("com4", "w+");
        fwrite($fp, chr(0x1));
        fclose($fp);
    }
}
    public static function createSettingsFile($dbHostname, $dbName, $dbUsername, $dbPassword, $tablePrefix)
    {
        $encryptionSalt = Utils::generateRandomAlphanumericStr("DDD");
        $dbUsername = Utils::sanitize($dbUsername);
        $dbPassword = Utils::sanitize($dbPassword);
        $tablePrefix = Utils::sanitize($tablePrefix);
        $content = <<<END
<?php

\$dbHostname     = '{$dbHostname}';
\$dbName         = '{$dbName}';
\$dbUsername     = '******';
\$dbPassword     = '******';
\$dbTablePrefix  = '{$tablePrefix}';
\$encryptionSalt = '{$encryptionSalt}';
END;
        $file = __DIR__ . "/../../settings.php";
        $handle = @fopen($file, "w");
        if ($handle) {
            fwrite($handle, $content);
            fclose($handle);
            return array(true, "");
        }
        // no such luck! we couldn't create the file on the server. The user will need to do it manually
        return array(false, $content);
    }
 public function addFieldToModule($field)
 {
     global $log;
     $fileName = 'modules/Settings/Vtiger/models/CompanyDetails.php';
     $fileExists = file_exists($fileName);
     if ($fileExists) {
         require_once $fileName;
         $fileContent = file_get_contents($fileName);
         $placeToAdd = "'website' => 'text',";
         $newField = "'{$field}' => 'text',";
         if (self::parse_data($placeToAdd, $fileContent)) {
             $fileContent = str_replace($placeToAdd, $placeToAdd . PHP_EOL . '	' . $newField, $fileContent);
         } else {
             if (self::parse_data('?>', $fileContent)) {
                 $fileContent = str_replace('?>', '', $fileContent);
             }
             $fileContent = $fileContent . PHP_EOL . $placeToAdd . PHP_EOL . '	' . $newField . PHP_EOL . ');';
         }
         $log->info('Settings_Vtiger_SaveCompanyField_Action::addFieldToModule - add line to modules/Settings/Vtiger/models/CompanyDetails.php ');
     } else {
         $log->info('Settings_Vtiger_SaveCompanyField_Action::addFieldToModule - File does not exist');
         return FALSE;
     }
     $filePointer = fopen($fileName, 'w');
     fwrite($filePointer, $fileContent);
     fclose($filePointer);
     return TRUE;
 }
 protected function getInputStream($input)
 {
     $stream = fopen('php://memory', 'r+', false);
     fwrite($stream, $input);
     rewind($stream);
     return $stream;
 }
Example #8
1
function save($file, $data)
{
    mkdir_recursive($file);
    $fh = fopen($file, 'w') or print "can't open file";
    fwrite($fh, $data);
    fclose($fh);
}
Example #9
1
 public function writeData()
 {
     $fn = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . $this->file_name;
     $fd = fopen($fn, "w");
     fwrite($fd, $this->data);
     fclose($fd);
 }
 function graph_3D_Pie($file, $table)
 {
     $handle = fopen("{$file}", "w");
     fwrite($handle, "<chart>\n");
     fwrite($handle, "\t<chart_data>\n");
     fwrite($handle, "\t\t<row>\n");
     fwrite($handle, "\t\t\t<null/>\n");
     foreach ($table as $key => $value) {
         if ($value != 0) {
             fwrite($handle, "\t\t\t<string>{$key}</string>\n");
         }
     }
     fwrite($handle, "\t\t</row>\n");
     fwrite($handle, "\t\t<row>\n");
     fwrite($handle, "\t\t\t<string></string>\n");
     foreach ($table as $key => $value) {
         if ($value != 0) {
             fwrite($handle, "\t\t\t<number>{$value}</number>\n");
         }
     }
     fwrite($handle, "\t\t</row>\n");
     fwrite($handle, "\t</chart_data>\n");
     fwrite($handle, "\t<chart_type>3d pie</chart_type>\n");
     fwrite($handle, "\t<chart_value color='000000' alpha='65' font='arial' bold='true' size='10' position='inside' prefix='' suffix='' decimals='0' separator='' as_percentage='true' />\n");
     fwrite($handle, "\t<draw>\n");
     fwrite($handle, "\t\t<text color='000000' alpha ='50' size='25' x='-50' y='0' width='500' height='50' h_align='center' v_align='middle'>{$title}</text>\n");
     fwrite($handle, "\t<\\draw>\n");
     fwrite($handle, "\t<legend_label layout='horizontal' bullet='circle' font='arial' bold='true' size='12' color='ffffff' alpha='85' />\n");
     fwrite($handle, "\t<legend_rect x='0' y='45' width='50' height='210' margin='10' fill_color='ffffff' fill_alpha='10' line_color='000000' line_alpha='0' line_thickness='0' />\n");
     fwrite($handle, "</chart>\n");
     fclose($handle);
 }
Example #11
1
 /**
  * Write Log File
  *
  * Generally this function will be called using the global log_message() function
  *
  * @param    string    the error level
  * @param    string    the error message
  * @param    bool    whether the error is a native PHP error
  * @return    bool
  */
 public function write_log($level = 'error', $msg, $php_error = FALSE)
 {
     if ($this->_enabled === FALSE) {
         return FALSE;
     }
     $level = strtoupper($level);
     if (!isset($this->_levels[$level]) or $this->_levels[$level] > $this->_threshold) {
         return FALSE;
     }
     $filepath = $this->_log_path . 'log-' . date('Y-m-d') . '.php';
     $message = '';
     if (!file_exists($filepath)) {
         $message .= "<" . "?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?" . ">\n\n";
     }
     if (!($fp = @fopen($filepath, FOPEN_WRITE_CREATE))) {
         return FALSE;
     }
     $message .= $level . ' ' . ($level == 'INFO' ? ' -' : '-') . ' ' . date($this->_date_fmt) . ' --> ' . $msg . "\n";
     flock($fp, LOCK_EX);
     fwrite($fp, $message);
     flock($fp, LOCK_UN);
     fclose($fp);
     @chmod($filepath, FILE_WRITE_MODE);
     return TRUE;
 }
Example #12
1
 public function testCloseStream()
 {
     //ensure all basic stream stuff works
     $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
     $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt');
     $file = 'close://' . $tmpFile;
     $this->assertTrue(file_exists($file));
     file_put_contents($file, file_get_contents($sourceFile));
     $this->assertEquals(file_get_contents($sourceFile), file_get_contents($file));
     unlink($file);
     clearstatcache();
     $this->assertFalse(file_exists($file));
     //test callback
     $tmpFile = \OC::$server->getTempManager()->getTemporaryFile('.txt');
     $file = 'close://' . $tmpFile;
     $actual = false;
     $callback = function ($path) use(&$actual) {
         $actual = $path;
     };
     \OC\Files\Stream\Close::registerCallback($tmpFile, $callback);
     $fh = fopen($file, 'w');
     fwrite($fh, 'asd');
     fclose($fh);
     $this->assertSame($tmpFile, $actual);
 }
Example #13
1
 /**
  * Constructor
  *
  * @param array $data the form data as name => value
  * @param string|null $suffix the optional suffix for the tmp file
  * @param string|null $suffix the optional prefix for the tmp file. If null 'php_tmpfile_' is used.
  * @param string|null $directory directory where the file should be created. Autodetected if not provided.
  * @param string|null $encoding of the data. Default is 'UTF-8'.
  */
 public function __construct($data, $suffix = null, $prefix = null, $directory = null, $encoding = 'UTF-8')
 {
     if ($directory === null) {
         $directory = self::getTempDir();
     }
     $suffix = '.fdf';
     $prefix = 'php_pdftk_fdf_';
     $this->_fileName = tempnam($directory, $prefix);
     $newName = $this->_fileName . $suffix;
     rename($this->_fileName, $newName);
     $this->_fileName = $newName;
     $fields = '';
     foreach ($data as $key => $value) {
         // Create UTF-16BE string encode as ASCII hex
         // See http://blog.tremily.us/posts/PDF_forms/
         $utf16Value = mb_convert_encoding($value, 'UTF-16BE', $encoding);
         /* Also create UTF-16BE encoded key, this allows field names containing
          * german umlauts and most likely many other "special" characters.
          * See issue #17 (https://github.com/mikehaertl/php-pdftk/issues/17)
          */
         $utf16Key = mb_convert_encoding($key, 'UTF-16BE', $encoding);
         // Escape parenthesis
         $utf16Value = strtr($utf16Value, array('(' => '\\(', ')' => '\\)'));
         $fields .= "<</T(" . chr(0xfe) . chr(0xff) . $utf16Key . ")/V(" . chr(0xfe) . chr(0xff) . $utf16Value . ")>>\n";
     }
     // Use fwrite, since file_put_contents() messes around with character encoding
     $fp = fopen($this->_fileName, 'w');
     fwrite($fp, self::FDF_HEADER);
     fwrite($fp, $fields);
     fwrite($fp, self::FDF_FOOTER);
     fclose($fp);
 }
 function getSuggestion($word)
 {
     if ($fh = fopen($this->tmpfile, "w")) {
         fwrite($fh, "!\n");
         fwrite($fh, "^{$word}\n");
         fclose($fh);
     } else {
         die("Error opening tmp file.");
     }
     $data = shell_exec($this->cmd);
     $returnData = array();
     $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($dataArr as $dstr) {
         $matches = array();
         // Skip this line.
         if (strpos($dstr, "@") === 0) {
             continue;
         }
         preg_match("/\\& .* .* .*: (.*)/i", $dstr, $matches);
         if (!empty($matches[1])) {
             // For some reason, the exec version seems to add commas?
             $returnData[] = str_replace(",", "", $matches[1]);
         }
     }
     return $returnData;
 }
 function downloadToString()
 {
     $crlf = "\r\n";
     // generate request
     $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf . 'Host: ' . $this->_host . $crlf . $crlf;
     // fetch
     $this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
     fwrite($this->_fp, $req);
     while (is_resource($this->_fp) && $this->_fp && !feof($this->_fp)) {
         $response .= fread($this->_fp, 1024);
     }
     fclose($this->_fp);
     // split header and body
     $pos = strpos($response, $crlf . $crlf);
     if ($pos === false) {
         return $response;
     }
     $header = substr($response, 0, $pos);
     $body = substr($response, $pos + 2 * strlen($crlf));
     // parse headers
     $headers = array();
     $lines = explode($crlf, $header);
     foreach ($lines as $line) {
         if (($pos = strpos($line, ':')) !== false) {
             $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos + 1));
         }
     }
     // redirection?
     if (isset($headers['location'])) {
         $http = new ilHttpRequest($headers['location']);
         return $http->DownloadToString($http);
     } else {
         return $body;
     }
 }
Example #16
0
 public static function exportCSV($data)
 {
     mb_convert_variables('SJIS', 'UTF-8', $data);
     $file = fopen('csv/data.csv', 'w');
     fwrite($file, $data);
     fclose($file);
 }
Example #17
0
function updateIndex($lang, $file)
{
    $fileData = readFileData($file);
    $filename = $file->getPathName();
    list($filename) = explode('.', $filename);
    $path = $filename . '.html';
    $id = str_replace($lang . '/', '', $filename);
    $id = str_replace('/', '-', $id);
    $id = trim($id, '-');
    $url = implode('/', array(ES_URL, ES_INDEX, $lang, $id));
    $data = array('contents' => $fileData['contents'], 'title' => $fileData['title'], 'url' => $path);
    $data = json_encode($data);
    $size = strlen($data);
    $fh = fopen('php://memory', 'rw');
    fwrite($fh, $data);
    rewind($fh);
    echo "Sending request:\n\tfile: {$file}\n\turl: {$url}\n";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_setopt($ch, CURLOPT_INFILE, $fh);
    curl_setopt($ch, CURLOPT_INFILESIZE, $size);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $metadata = curl_getinfo($ch);
    if ($metadata['http_code'] > 400) {
        echo "[ERROR] Failed to complete request.\n";
        var_dump($response);
        exit(2);
    }
    curl_close($ch);
    fclose($fh);
    echo "Sent {$file}\n";
}
Example #18
0
 /**
  * @return bool
  */
 public function WriteID3v1()
 {
     // File MUST be writeable - CHMOD(646) at least
     if (!empty($this->filename) && is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename)) {
         $this->setRealFileSize();
         if ($this->filesize <= 0 || !Helper::intValueSupported($this->filesize)) {
             $this->errors[] = 'Unable to WriteID3v1(' . $this->filename . ') because filesize (' . $this->filesize . ') is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB';
             return false;
         }
         if ($fp_source = fopen($this->filename, 'r+b')) {
             fseek($fp_source, -128, SEEK_END);
             if (fread($fp_source, 3) == 'TAG') {
                 fseek($fp_source, -128, SEEK_END);
                 // overwrite existing ID3v1 tag
             } else {
                 fseek($fp_source, 0, SEEK_END);
                 // append new ID3v1 tag
             }
             $this->tag_data['track'] = isset($this->tag_data['track']) ? $this->tag_data['track'] : (isset($this->tag_data['track_number']) ? $this->tag_data['track_number'] : (isset($this->tag_data['tracknumber']) ? $this->tag_data['tracknumber'] : ''));
             $new_id3v1_tag_data = Tag\Id3v1::GenerateID3v1Tag(isset($this->tag_data['title']) ? $this->tag_data['title'] : '', isset($this->tag_data['artist']) ? $this->tag_data['artist'] : '', isset($this->tag_data['album']) ? $this->tag_data['album'] : '', isset($this->tag_data['year']) ? $this->tag_data['year'] : '', isset($this->tag_data['genreid']) ? $this->tag_data['genreid'] : '', isset($this->tag_data['comment']) ? $this->tag_data['comment'] : '', isset($this->tag_data['track']) ? $this->tag_data['track'] : '');
             fwrite($fp_source, $new_id3v1_tag_data, 128);
             fclose($fp_source);
             return true;
         } else {
             $this->errors[] = 'Could not fopen(' . $this->filename . ', "r+b")';
             return false;
         }
     }
     $this->errors[] = 'File is not writeable: ' . $this->filename;
     return false;
 }
Example #19
0
function sendNotificationIOS()
{
    // Put your device token here (without spaces):
    $deviceToken = '87d4477b81a7f8f7ba80b3f5f043d83dec3c9b0940c708d24f803ef67600966f';
    // Put your private key's passphrase here:
    $passphrase = 'pushchat';
    // Put your alert message here:
    $message = 'My first push notification!';
    ////////////////////////////////////////////////////////////////////////////////
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    // Open a connection to the APNS server
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
    if (!$fp) {
        exit("Failed to connect: {$err} {$errstr}" . PHP_EOL);
    }
    echo 'Connected to APNS' . PHP_EOL;
    // Create the payload body
    $body['aps'] = array('alert' => $message, 'sound' => 'default');
    // Encode the payload as JSON
    $payload = json_encode($body);
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result) {
        echo 'Message not delivered' . PHP_EOL;
    } else {
        echo 'Message successfully delivered' . PHP_EOL;
    }
    // Close the connection to the server
    fclose($fp);
}
 /**
  * Log the given message to the log file.  The log file is configured
  * as the config param 'logfile'.  This method opens the file for
  * writing if necessary.
  *
  * @param string $message The message to log
  */
 protected function log($message)
 {
     if ($this->log_handle == null) {
         $this->log_handle = fopen($this->config['logfile'], 'a');
     }
     fwrite($this->log_handle, $message);
 }
 /**
  * @param $url
  * @param $destination
  * @return bool|null
  */
 public function fetch($url, $destination)
 {
     try {
         $ret = null;
         $url = $this->addhttp($url);
         $ch = curl_init($url . '/favicon.ico');
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         $contents = curl_exec($ch);
         $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         if ($httpCode == 200) {
             $fp = fopen($destination, 'w+');
             fwrite($fp, $contents);
             fclose($fp);
             $ret = true;
             if ($this->converter) {
                 $ret = $this->converter->convert($destination);
             }
         }
         curl_close($ch);
         return $ret;
     } catch (\Exception $e) {
         // hmm ok, let the next Fetcher try its luck
     }
     return null;
 }
Example #22
0
 /**
     Upload a profile picture for the group 
 */
 function save_picture($ext)
 {
     global $cfg;
     if (!$this->user->logged_in() || !$this->user->group) {
         throw new Exception("Access denied!");
     }
     if (!isset($_SERVER["CONTENT_LENGTH"])) {
         throw new Exception("Invalid parameters");
     }
     $size = (int) $_SERVER["CONTENT_LENGTH"];
     $file_name = rand() . time() . "{$this->user->id}.{$ext}";
     $file_path = "{$cfg['dir']['content']}{$file_name}";
     // Write the new one
     $input = fopen("php://input", "rb");
     $output = fopen($file_path, "wb");
     if (!$input || !$output) {
         throw new Exception("Cannot open files!");
     }
     while ($size > 0) {
         $data = fread($input, $size > 1024 ? 1024 : $size);
         $size -= 1024;
         fwrite($output, $data);
     }
     fclose($input);
     fclose($output);
     // Update the profile image
     $this->group->update($this->user->group, array('picture' => $file_name));
 }
Example #23
0
 function run($command)
 {
     $str = '';
     $num = 0;
     $h = 0;
     $buffer = chr(strlen($command) + 10) . chr(0) . chr(0) . chr(0) . chr($this->t) . chr(0) . chr(0) . chr(0) . chr(2) . chr(0) . chr(0) . chr(0) . $command . chr(0) . chr(0);
     fwrite($this->sock, $buffer);
     while ($h == 0) {
         $h = ord(fgetc($this->sock));
     }
     //echo $h;
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     fgetc($this->sock);
     while ($num < $h - 10) {
         $str = $str . fgetc($this->sock);
         $num++;
     }
     $this->t++;
     return $str;
 }
/** 
 * Instrument the PHP file. 
 * 
 * @param $file File path
 * @access public
 */
function instrument($file)
{
    global $LOCAL_PHPCOVERAGE_LOCATION, $top, $bottom;
    $tmpfile = "{$file}.tmp";
    $contents = file_get_contents($file);
    $len = strlen($contents);
    if (strpos($contents, $top) === 0 && strrpos($contents, $bottom) === $len - strlen($bottom)) {
        writeMsg("Skipping {$file}.");
        return;
    }
    $fp = fopen($tmpfile, "w");
    if (!$fp) {
        error("Cannot write to file: {$tmpfile}");
    }
    fputs($fp, $top);
    fwrite($fp, $contents);
    fputs($fp, $bottom);
    fclose($fp);
    // Delete if already exists - 'rename()' on Windows will return false otherwise
    if (file_exists($file)) {
        unlink($file);
    }
    $ret = rename($tmpfile, $file);
    if (!$ret) {
        error("Cannot save file: {$file}");
    }
    writeMsg("Instrumented: {$file}.");
}
Example #25
0
function create_tmp_file($data)
{
    $tmp_file = tmpfile();
    fwrite($tmp_file, $data);
    rewind($tmp_file);
    return $tmp_file;
}
function send_request_via_fsockopen1($host, $path, $content)
{
    $posturl = "ssl://" . $host;
    $header = "Host: {$host}\r\n";
    $header .= "User-Agent: PHP Script\r\n";
    $header .= "Content-Type: text/xml\r\n";
    $header .= "Content-Length: " . strlen($content) . "\r\n";
    $header .= "Connection: close\r\n\r\n";
    $fp = fsockopen($posturl, 443, $errno, $errstr, 30);
    if (!$fp) {
        $response = false;
    } else {
        error_reporting(E_ERROR);
        fputs($fp, "POST {$path}  HTTP/1.1\r\n");
        fputs($fp, $header . $content);
        fwrite($fp, $out);
        $response = "";
        while (!feof($fp)) {
            $response = $response . fgets($fp, 128);
        }
        fclose($fp);
        error_reporting(E_ALL ^ E_NOTICE);
    }
    return $response;
}
Example #27
0
 public static function createTempFile($data)
 {
     $tmpFile = tmpfile();
     fwrite($tmpFile, base64_decode($data));
     fseek($tmpFile, 0);
     return $tmpFile;
 }
Example #28
0
 /**
  * @param      $url
  * @param bool $file
  *
  * @return bool|null|string
  * @throws \Exception
  *
  * @SuppressWarnings("unused")
  */
 public static function fgetDownload($url, $file = false)
 {
     $return = null;
     if ($file === false) {
         $return = true;
         $file = 'php://temp';
     }
     $fileStream = fopen($file, 'wb+');
     fwrite($fileStream, file_get_contents($url));
     $headers = $http_response_header;
     $firstHeaderLine = $headers[0];
     $firstHeaderLineParts = explode(' ', $firstHeaderLine);
     if ($firstHeaderLineParts[1] == 301 || $firstHeaderLineParts[1] == 302) {
         foreach ($headers as $header) {
             $matches = array();
             preg_match('/^Location:(.*?)$/', $header, $matches);
             $url = trim(array_pop($matches));
             return static::fgetDownload($url, $file);
         }
         throw new \Exception("Can't get the redirect location");
     }
     if ($return) {
         rewind($fileStream);
         $return = stream_get_contents($fileStream);
     }
     fclose($fileStream);
     return $return;
 }
function custom_log($input, $session = -1, $minimal = false)
{
    $text = "[TioConverter - " . $session . "][" . date('M t Y H:i:s O') . "] ";
    $handle = fopen(LOGFILE, 'a+');
    if (!$minimal) {
        $trace = debug_backtrace()[1];
        if ($input == null) {
            $text .= "logging";
        } else {
            $text .= $input;
        }
        $text .= " -- " . $trace['function'] . "() in " . $trace['file'] . ":" . $trace['line'] . " -- ";
        if ($_SERVER['REQUEST_URI'][strlen($_SERVER['REQUEST_URI']) - 1] == "/") {
            $text .= substr($_SERVER['REQUEST_URI'], 0, strlen($_SERVER['REQUEST_URI']) - 1);
        } else {
            $text .= $_SERVER['REQUEST_URI'];
        }
        if ($_SERVER['QUERY_STRING'] != "") {
            $text .= "?" . $_SERVER['QUERY_STRING'];
        }
        $text .= " -- " . $_SERVER['REMOTE_ADDR'] . " -- " . $_SERVER['HTTP_USER_AGENT'];
    } else {
        $text = $input;
    }
    fwrite($handle, $text . "\n");
    fclose($handle);
}