Ejemplo n.º 1
0
function JB_move_uploaded_attachment($mail_id, $att_file, $from_name)
{
    $mail_id = (int) $mail_id;
    $att_tmp = $_FILES[$att_file]['tmp_name'];
    $temp = explode('.', $_FILES[$att_file]['name']);
    $ext = array_pop($temp);
    if (!file_exists(JB_FILE_PATH . "temp/")) {
        mkdir(JB_FILE_PATH . "temp/", JB_NEW_DIR_CHMOD);
        //chmod(JB_FILE_PATH."temp/", JB_NEW_DIR_CHMOD);
    }
    if (strpos(strtoupper(PHP_OS), 'WIN') !== false) {
        // sometimes the dir can have double slashes on Win, remove 'em
        $att_tmp = str_replace('\\\\', '\\', $att_tmp);
    }
    // strip out non-alphanumeric characters from from_name
    $from_name = preg_replace('/[^a-z^0-9^&^;^.^#]+/i', "", $from_name);
    $from_name = JB_clean_str($from_name);
    $ext = preg_replace('/[^a-z^0-9]+/i', "", $ext);
    $new_name = JB_FILE_PATH . "temp/{$from_name}" . $mail_id . "{$att_file}." . $ext;
    if (move_uploaded_file($att_tmp, $new_name)) {
        chmod($new_name, JB_NEW_FILE_CHMOD);
    } else {
        //echo htmlentities('Could not move the image form the temp directory.  (FROM: '.$_FILES[$field_id]['tmp_name'].' ->> TO: '.$uploadfile.') ').PHP_OS."<br>\n";
        switch ($_FILES[$field_id]["error"]) {
            case UPLOAD_ERR_OK:
                break;
            case UPLOAD_ERR_INI_SIZE:
                jb_custom_error_handler('upload', "The uploaded file exceeds the upload_max_filesize directive (" . ini_get("upload_max_filesize") . ") in php.ini.", __FILE__, __LINE__, $vars);
                break;
            case UPLOAD_ERR_FORM_SIZE:
                jb_custom_error_handler('upload', "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.", __FILE__, 0, $vars);
                break;
            case UPLOAD_ERR_PARTIAL:
                jb_custom_error_handler('upload', "The uploaded file was only partially uploaded.", __FILE__, 0, $vars);
                break;
            case UPLOAD_ERR_NO_FILE:
                jb_custom_error_handler('upload', "No file was uploaded.", __FILE__, __LINE__, $vars);
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                jb_custom_error_handler('upload', "Missing a temporary folder.", __FILE__, __LINE__, $vars);
                break;
            case UPLOAD_ERR_CANT_WRITE:
                jb_custom_error_handler('upload', "Failed to write file to disk", __FILE__, __LINE__, $vars);
                break;
            default:
                jb_custom_error_handler('upload', "Unknown File Error", __FILE__, __LINE__, $vars);
        }
    }
    return $new_name;
}
Ejemplo n.º 2
0
 function set($key, &$data, $ttl = false)
 {
     $file_name = $this->get_file_name($key);
     $file_existed = file_exists($file_name);
     // Opening the file in read/write mode
     $h = @fopen($file_name, 'a+');
     if (!$h) {
         return false;
     }
     if (!flock($h, LOCK_EX)) {
         // exclusive lock, will get released when the file is closed
         return false;
         fclose($h);
     }
     fseek($h, 0);
     // go to the beginning of the file
     // truncate the file
     ftruncate($h, 0);
     if ($ttl) {
         $ttl += time();
     }
     // Serializing along with the TTL
     $str = serialize(array($ttl, $data));
     if (fwrite($h, $str, strlen($str)) === false) {
         return false;
     }
     fflush($h);
     fclose($h);
     if (!$file_existed) {
         // chmod the file only if it didn't exist before calling this function
         if (!@chmod($file_name, JB_NEW_FILE_CHMOD)) {
             $req = var_export($_REQUEST, true);
             jb_custom_error_handler('sql', jb_escape_html('tried to chmod this file: ' . $file_name . ' key was:' . $key . ' chmod:' . decoct(JB_NEW_FILE_CHMOD) . $req), __FILE__, 0, $vars);
         }
     }
     return true;
 }
Ejemplo n.º 3
0
function JB_saveImage($field_id, $user_id = false)
{
    if ($user_id === false) {
        $user_id = $_SESSION['JB_ID'];
    }
    $a = explode(".", JB_clean_str($_FILES[$field_id]['name']));
    if (sizeof($a) < 2) {
        // must have name and extension
        return false;
    }
    $ext = strtolower(array_pop($a));
    $name = strtolower(array_shift($a));
    if (!$name) {
        return false;
    }
    $name = $user_id . "_" . $name;
    // prefix the file with the user id
    $name = preg_replace('#[^a-z^0-9]+#i', "_", $name);
    // strip out unwanted characters
    $ext = preg_replace('#[^a-z^0-9]+#i', "_", $ext);
    // strip out unwanted characters
    $new_name = $name . time() . "." . $ext;
    //$new_name = $name.".".$ext;
    $uploadfile = jb_provision_archive_path($new_name, 'IMAGE');
    $thumbfile = jb_provision_archive_path($new_name, 'THUMB');
    if (strpos(strtoupper(PHP_OS), 'WIN') !== false) {
        // sometimes the dir can have double slashes on Win, remove 'em
        $_FILES[$field_id]['tmp_name'] = str_replace('\\\\', '\\', $_FILES[$field_id]['tmp_name']);
    }
    if (move_uploaded_file($_FILES[$field_id]['tmp_name'], $uploadfile)) {
        //if unix, update permissions
        chmod($uploadfile, JB_NEW_FILE_CHMOD);
        // plugins can hook here to do extra processing on the file
        JBPLUG_do_callback('save_image', $uploadfile, $field_id, $user_id);
    } else {
        //echo htmlentities('Could not move the image form the temp directory.  (FROM: '.$_FILES[$field_id]['tmp_name'].' ->> TO: '.$uploadfile.') ').PHP_OS."<br>\n";
        switch ($_FILES[$field_id]["error"]) {
            case UPLOAD_ERR_OK:
                jb_custom_error_handler('upload', "Uploaded the file OK, but the move failed", __FILE__, __LINE__, $vars);
                break;
            case UPLOAD_ERR_INI_SIZE:
                jb_custom_error_handler('upload', "The uploaded file exceeds the upload_max_filesize directive (" . ini_get("upload_max_filesize") . ") in php.ini.", __FILE__, __LINE__, $vars);
                break;
            case UPLOAD_ERR_FORM_SIZE:
                jb_custom_error_handler('upload', "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.", __FILE__, 0, $vars);
                break;
            case UPLOAD_ERR_PARTIAL:
                jb_custom_error_handler('upload', "The uploaded file was only partially uploaded.", __FILE__, 0, $vars);
                break;
            case UPLOAD_ERR_NO_FILE:
                jb_custom_error_handler('upload', "No file was uploaded.", __FILE__, __LINE__, $vars);
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                jb_custom_error_handler('upload', "Missing a temporary folder.", __FILE__, __LINE__, $vars);
                break;
            case UPLOAD_ERR_CANT_WRITE:
                jb_custom_error_handler('upload', "Failed to write file to disk", __FILE__, __LINE__, $vars);
                break;
            default:
                jb_custom_error_handler('upload', "Unknown File Error", __FILE__, __LINE__, $vars);
        }
    }
    // resize
    JB_gd_resize_image($field_id, $uploadfile, $thumbfile);
    // use GD Library
    @chmod($thumbfile, JB_NEW_FILE_CHMOD);
    if (JB_KEEP_ORIGINAL_IMAGES == 'YES') {
        // resize the original image.
        if (!defined('JB_BIG_IMG_MAX_WIDTH')) {
            define('JB_BIG_IMG_MAX_WIDTH', 1000);
        }
        JB_gd_resize_image($field_id, $uploadfile, $thumbfile . '.tmp', JB_BIG_IMG_MAX_WIDTH);
        // use GD Library
        unlink($uploadfile);
        // move the original image to the upload_files/images/ directory
        copy($thumbfile . '.tmp', $uploadfile);
        unlink($thumbfile . '.tmp');
    } else {
        @unlink($uploadfile);
        // delete the original file.
    }
    return $new_name;
}
Ejemplo n.º 4
0
function JB_echo_db_error($error)
{
    if (defined('JB_HIDE_MYSQL_ERRORS') && JB_HIDE_MYSQL_ERRORS) {
        return;
    }
    if (strpos($error, 'show columns from') !== false) {
        // this is a diagnostic query, should still continue on error.
        return;
    }
    $http_url = $_SERVER['PHP_SELF'];
    // eg /ojo/admin/edit_config.php
    $http_url = str_replace('admin/', '', $http_url);
    if (strpos($error, "doesn't exist") !== false) {
        // looks like the database was not installed
        if (file_exists(dirname(__FILE__) . '/admin/install.php')) {
            $http_url = preg_replace('#/(/admin/)?[^/]+$#', '/admin/install.php', $http_url);
            JB_echo_install_info($http_url, $error);
            die;
        } elseif (basename($_SERVER['PHP_SELF']) !== 'edit_config.php') {
            $http_url = preg_replace('#/(/admin/)?[^/]+$#', '/admin/edit_config.php', $http_url);
            echo_edit_config_info($http_url, $error);
            die;
        }
    } else {
        if (JB_SET_CUSTOM_ERROR == 'YES') {
            ob_start();
            $trace = debug_backtrace();
            var_dump($trace['1']);
            $trace = ob_get_contents();
            ob_end_clean();
            $req = var_export($_REQUEST, true);
            if (function_exists('jb_escape_html')) {
                jb_custom_error_handler('sql', jb_escape_html($error . "\n" . $trace . "\n" . $req), __FILE__, 0, $vars);
            } else {
                jb_custom_error_handler('sql', htmlentities($error . "\n" . $trace . "\n" . $req), __FILE__, 0, $vars);
            }
        } else {
            if (function_exists('jb_escape_html')) {
                echo jb_escape_html($error);
            } else {
                echo htmlentities($error);
            }
        }
    }
}