コード例 #1
0
/**
 * Generates a random hashed and salted string.
 * @return type
 */
function generateRandomString($urlSafe = true, $length = 10)
{
    // Use date timestamp as salt.
    $rand = mt_rand();
    $salt = $rand . uniqid();
    $string = sha1($salt);
    $string = base64_encode($string);
    if ($urlSafe) {
        $string = makeUrlSafe($string);
    }
    $string = substr($string, 0, $length);
    return $string;
}
コード例 #2
0
ファイル: rpc.php プロジェクト: arthurwayne/wget-gui-light
/**
 * Get downloaded file data for user web access
 *
 * @since  0.1.6
 * @param  (string) Local file path
 * @return (array)
 */
function getFileDataForWebAccess($filename)
{
    $result = array();
    if (defined('DOWNLOAD_URL') && DOWNLOAD_URL !== '' && !empty($filename)) {
        $url = (string) DOWNLOAD_URL . makeUrlSafe($filename);
        $headers = @get_headers($url, 1);
        if ($headers !== false && strpos($headers[0], '200') !== false || strpos($headers[0], '304') !== false) {
            $result['access_url'] = $url;
            if (isset($headers['Content-Length']) && $headers['Content-Length'] > 0) {
                $result['size'] = intval($headers['Content-Length']);
            }
            if (isset($headers['Content-Type'])) {
                $result['content_type'] = $headers['Content-Type'];
            }
            if (isset($headers['Last-Modified'])) {
                $result['last_modified'] = $headers['Last-Modified'];
            }
            //$result['headers'] = $headers;
        }
    }
    return $result;
}