示例#1
0
function wrapImagesInline($htmlContent)
{
    global $_INLINED_IMAGES;
    $_INLINED_IMAGES = null;
    $replacedContent = imageRewriter($htmlContent, 'wrapImagesInline_rewriter($URL)');
    // Make the HTML part
    $headers["Content-Type"] = "text/html; charset=utf-8";
    $headers["Content-Transfer-Encoding"] = "quoted-printable";
    $multiparts[] = processHeaders($headers, QuotedPrintable_encode($replacedContent));
    // Make all the image parts
    global $_INLINED_IMAGES;
    foreach ($_INLINED_IMAGES as $url => $cid) {
        $multiparts[] = encodeFileForEmail($url, false, "inline", "Content-ID: <{$cid}>\n");
    }
    // Merge together in a multipart
    list($body, $headers) = encodeMultipart($multiparts, "multipart/related");
    return processHeaders($headers, $body);
}
示例#2
0
文件: utils.php 项目: semul/Osclass
/**
 * Download file using fsockopen
 *
 * @since 3.0
 * @param type $sourceFile
 * @param type $fileout
 */
function download_fsockopen($sourceFile, $fileout = null)
{
    // parse URL
    $aUrl = parse_url($sourceFile);
    $host = $aUrl['host'];
    if ('localhost' == strtolower($host)) {
        $host = '127.0.0.1';
    }
    $link = $aUrl['path'] . (isset($aUrl['query']) ? '?' . $aUrl['query'] : '');
    if (empty($link)) {
        $link .= '/';
    }
    $fp = @fsockopen($host, 80, $errno, $errstr, 30);
    if (!$fp) {
    } else {
        $out = "GET {$link} HTTP/1.1\r\n";
        $out .= "Host: {$host}\r\n";
        $out .= "Connection: Close\r\n\r\n";
        $out .= "\r\n";
        fwrite($fp, $out);
        $contents = '';
        while (!feof($fp)) {
            $contents .= fgets($fp, 1024);
        }
        // check redirections ?
        // if (redirections) then do request again
        $aResult = processResponse($contents);
        $headers = processHeaders($aResult['headers']);
        $location = @$headers['location'];
        if (isset($location) && $location != "") {
            $aUrl = parse_url($headers['location']);
            $host = $aUrl['host'];
            if ('localhost' == strtolower($host)) {
                $host = '127.0.0.1';
            }
            $requestPath = $aUrl['path'] . (isset($aUrl['query']) ? '?' . $aUrl['query'] : '');
            if (empty($requestPath)) {
                $requestPath .= '/';
            }
            download_fsockopen($host, $requestPath, $fileout);
        } else {
            $body = $aResult['body'];
            $transferEncoding = @$headers['transfer-encoding'];
            if ($transferEncoding == 'chunked') {
                $body = http_chunked_decode($aResult['body']);
            }
            if ($fileout != null) {
                $ff = @fopen($fileout, 'w+');
                fwrite($ff, $body);
                fclose($ff);
            } else {
                return $body;
            }
        }
        fclose($fp);
    }
}
示例#3
0
\************************************************/
$page = new WebPage($redirectIP . $_GET[$fileVar], true, $server, "URLproxyServer.php", $fileVar, $relDir);
/************************************************\
* This tells the WebPage object to open up a     *
* connection to the URL.                         *
*                                                *
* Note:                                          *
* This does not actually get the web page, just  *
* opens the connection for the headers.          *
\************************************************/
$page->openLink();
/************************************************\
* Process the headers so we know what kind of    *
* data we have (html/other)                      *
\************************************************/
$head = processHeaders($page->getHeaders(), $file, $mime_dl, $type, $isDown, $isHtml, $isImage);
/************************************************\
* This code replicates the headers that were     *
* sent when the class connected to the url.      *
*                                                *
* FIXME: extra headers need to be sent if we are *
* downloading the file.                          *
*                                                *
* GOTCHA?: need to check if http 1.1 will work   *
* correctly                                      *
\************************************************/
//foreach($head as $h) header($h);
/************************************************\
* This block of code displays the page to the    *
* user.                                          *
*                                                *
示例#4
0
文件: utils.php 项目: naneri/Osclass
/**
 * Download file using fsockopen
 *
 * @since 3.0
 * @param type $sourceFile
 * @param type $fileout
 */
function download_fsockopen($sourceFile, $fileout = null, $post_data = null)
{
    // parse URL
    $aUrl = parse_url($sourceFile);
    $host = $aUrl['host'];
    if ('localhost' == strtolower($host)) {
        $host = '127.0.0.1';
    }
    $link = $aUrl['path'] . (isset($aUrl['query']) ? '?' . $aUrl['query'] : '');
    if (empty($link)) {
        $link .= '/';
    }
    $fp = @fsockopen($host, 80, $errno, $errstr, 30);
    if (!$fp) {
        return false;
    } else {
        $ua = @$_SERVER['HTTP_USER_AGENT'] . ' Osclass (v.' . osc_version() . ')';
        $out = ($post_data != null && is_array($post_data) ? "POST" : "GET") . " {$link} HTTP/1.1\r\n";
        $out .= "Host: {$host}\r\n";
        $out .= "User-Agent: {$ua}\r\n";
        $out .= "Connection: Close\r\n\r\n";
        $out .= "\r\n";
        if ($post_data != null && is_array($post_data)) {
            $out .= http_build_query($post_data);
        }
        fwrite($fp, $out);
        $contents = '';
        while (!feof($fp)) {
            $contents .= fgets($fp, 1024);
        }
        fclose($fp);
        // check redirections ?
        // if (redirections) then do request again
        $aResult = processResponse($contents);
        $headers = processHeaders($aResult['headers']);
        $location = @$headers['location'];
        if (isset($location) && $location != "") {
            $aUrl = parse_url($headers['location']);
            $host = $aUrl['host'];
            if ('localhost' == strtolower($host)) {
                $host = '127.0.0.1';
            }
            $requestPath = $aUrl['path'] . (isset($aUrl['query']) ? '?' . $aUrl['query'] : '');
            if (empty($requestPath)) {
                $requestPath .= '/';
            }
            download_fsockopen($host, $requestPath, $fileout);
        } else {
            $body = $aResult['body'];
            $transferEncoding = @$headers['transfer-encoding'];
            if ($transferEncoding == 'chunked') {
                $body = http_chunked_decode($aResult['body']);
            }
            if ($fileout != null) {
                $ff = @fopen($fileout, 'w+');
                if ($ff !== FALSE) {
                    fwrite($ff, $body);
                    fclose($ff);
                    return true;
                } else {
                    return false;
                }
            } else {
                return $body;
            }
        }
    }
}