还是charset的老问题,数据库也用utf-8编码俩都统一成者乱乱的文字了

解决方案 »

  1.   

    可能要转成GB或GBK
    win系统的编码是unicode,和utf8还不一样
      

  2.   

    楼上怎么见得楼主用的win系统?
    建议改名
      

  3.   

    字段这样设计吧:
    ID:自增就不用说了。
    FileName:文件名,上传前文件名,或表单提交指定命名,中文注意数据库编码问题。
    FileAddr:文件路径,文件存放路径+文件名,这个文件名你可以自定义,比如time()md5()等。
    其他字段自己补充。
      

  4.   

    数据库的字符集是utf8的,这个没有问题。只是上传到硬盘中的文件名不正确。
      

  5.   

    下面是我用的上传的类文件,请高手分析一下问题所在呀。
    <br/>
    <pre style="color:green">
    <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
    /**
     * Code Igniter
     *
     * An open source application development framework for PHP 4.3.2 or newer
     *
     * @package CodeIgniter
     * @author Rick Ellis
     * @copyright Copyright (c) 2006, pMachine, Inc.
     * @license http://www.codeignitor.com/user_guide/license.html
     * @link http://www.codeigniter.com
     * @since Version 1.0
     * @filesource
     */// ------------------------------------------------------------------------/**
     * File Uploading Class
     *
     * @package CodeIgniter
     * @subpackage Libraries
     * @category Uploads
     * @author Rick Ellis
     * @link http://www.codeigniter.com/user_guide/libraries/file_uploading.html
     */
    class CI_Upload {

    var $max_size = 0;
    var $max_width = 0;
    var $max_height = 0;
    var $allowed_types = "";
    var $file_temp = "";
    var $file_name = "";
    var $orig_name = "";
    var $file_type = "";
    var $file_size = "";
    var $file_ext = "";
    var $upload_path = "";
    var $overwrite = FALSE;
    var $encrypt_name = FALSE;
    var $is_image = FALSE;
    var $image_width = '';
    var $image_height = '';
    var $image_type = '';
    var $image_size_str = '';
    var $error_msg = array();
    var $mimes = array();
    var $remove_spaces = TRUE;
    var $xss_clean = FALSE;
    var $temp_prefix = "temp_file_";

    /**
     * Constructor
     *
     * @access public
     */
    function CI_Upload($props = array())
    {
    if (count($props) > 0)
    {
    $this->initialize($props);
    }

    log_message('debug', "Upload Class Initialized");
    }

    // --------------------------------------------------------------------

    /**
     * Initialize preferences
     *
     * @access public
     * @param array
     * @return void
     */
    function initialize($config = array())
    {
    $defaults = array(
    'max_size' => 0,
    'max_width' => 0,
    'max_height' => 0,
    'allowed_types' => "",
    'file_temp' => "",
    'file_name' => "",
    'orig_name' => "",
    'file_type' => "",
    'file_size' => "",
    'file_ext' => "",
    'upload_path' => "",
    'overwrite' => FALSE,
    'encrypt_name' => FALSE,
    'is_image' => FALSE,
    'image_width' => '',
    'image_height' => '',
    'image_type' => '',
    'image_size_str' => '',
    'error_msg' => array(),
    'mimes' => array(),
    'remove_spaces' => TRUE,
    'xss_clean' => FALSE,
    'temp_prefix' => "temp_file_"
    );


    foreach ($defaults as $key => $val)
    {
    if (isset($config[$key]))
    {
    $method = 'set_'.$key;
    if (method_exists($this, $method))
    {
    $this->$method($config[$key]);
    }
    else
    {
    $this->$key = $config[$key];
    }
    }
    else
    {
    $this->$key = $val;
    }
    }
    }

    // --------------------------------------------------------------------

    /**
     * Perform the file upload
     *
     * @access public
     * @return bool
     */
    function do_upload($field = 'userfile')
    {
    // Is $_FILES[$field] set? If not, no reason to continue.
    if ( ! isset($_FILES[$field]))
    {
    $this->set_error('upload_userfile_not_set');
    return FALSE;
    }

    // Is the upload path valid?
    if ( ! $this->validate_upload_path())
    {
    return FALSE;
    }

    // Was the file able to be uploaded? If not, determine the reason why.
    if ( ! is_uploaded_file($_FILES[$field]['tmp_name']))
    {
    $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error)
    {
    case 1  :   $this->set_error('upload_file_exceeds_limit');
    break;
    case 3  :   $this->set_error('upload_file_partial');
    break;
    case 4  :   $this->set_error('upload_no_file_selected');
    break;
    default :   $this->set_error('upload_no_file_selected');
    break;
    } return FALSE;
    }</pre>
      

  6.   

    不好意思,上面发的不是真正的原文。下面的几个回复才是:
    <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
    /**
     * Code Igniter
     *
     * An open source application development framework for PHP 4.3.2 or newer
     *
     * @package CodeIgniter
     * @author Rick Ellis
     * @copyright Copyright (c) 2006, pMachine, Inc.
     * @license http://www.codeignitor.com/user_guide/license.html
     * @link http://www.codeigniter.com
     * @since Version 1.0
     * @filesource
     */// ------------------------------------------------------------------------/**
     * File Uploading Class
     *
     * @package CodeIgniter
     * @subpackage Libraries
     * @category Uploads
     * @author Rick Ellis
     * @link http://www.codeigniter.com/user_guide/libraries/file_uploading.html
     */
    class CI_Upload {

    var $max_size = 0;
    var $max_width = 0;
    var $max_height = 0;
    var $allowed_types = "";
    var $file_temp = "";
    var $file_name = "";
    var $orig_name = "";
    var $file_type = "";
    var $file_size = "";
    var $file_ext = "";
    var $upload_path = "";
    var $overwrite = FALSE;
    var $encrypt_name = FALSE;
    var $is_image = FALSE;
    var $image_width = '';
    var $image_height = '';
    var $image_type = '';
    var $image_size_str = '';
    var $error_msg = array();
    var $mimes = array();
    var $remove_spaces = TRUE;
    var $xss_clean = FALSE;
    var $temp_prefix = "temp_file_";

    /**
     * Constructor
     *
     * @access public
     */
    function CI_Upload($props = array())
    {
    if (count($props) > 0)
    {
    $this->initialize($props);
    }

    log_message('debug', "Upload Class Initialized");
    }

    // --------------------------------------------------------------------

    /**
     * Initialize preferences
     *
     * @access public
     * @param array
     * @return void
     */
    function initialize($config = array())
    {
    $defaults = array(
    'max_size' => 0,
    'max_width' => 0,
    'max_height' => 0,
    'allowed_types' => "",
    'file_temp' => "",
    'file_name' => "",
    'orig_name' => "",
    'file_type' => "",
    'file_size' => "",
    'file_ext' => "",
    'upload_path' => "",
    'overwrite' => FALSE,
    'encrypt_name' => FALSE,
    'is_image' => FALSE,
    'image_width' => '',
    'image_height' => '',
    'image_type' => '',
    'image_size_str' => '',
    'error_msg' => array(),
    'mimes' => array(),
    'remove_spaces' => TRUE,
    'xss_clean' => FALSE,
    'temp_prefix' => "temp_file_"
    );


    foreach ($defaults as $key => $val)
    {
    if (isset($config[$key]))
    {
    $method = 'set_'.$key;
    if (method_exists($this, $method))
    {
    $this->$method($config[$key]);
    }
    else
    {
    $this->$key = $config[$key];
    }
    }
    else
    {
    $this->$key = $val;
    }
    }
    }

    // --------------------------------------------------------------------

    /**
     * Perform the file upload
     *
     * @access public
     * @return bool
     */
    function do_upload($field = 'userfile')
    {
    // Is $_FILES[$field] set? If not, no reason to continue.
    if ( ! isset($_FILES[$field]))
    {
    $this->set_error('upload_userfile_not_set');
    return FALSE;
    }

    // Is the upload path valid?
    if ( ! $this->validate_upload_path())
    {
    return FALSE;
    }

    // Was the file able to be uploaded? If not, determine the reason why.
    if ( ! is_uploaded_file($_FILES[$field]['tmp_name']))
    {
    $error = ( ! isset($_FILES[$field]['error'])) ? 4 : $_FILES[$field]['error']; switch($error)
    {
    case 1  :   $this->set_error('upload_file_exceeds_limit');
    break;
    case 3  :   $this->set_error('upload_file_partial');
    break;
    case 4  :   $this->set_error('upload_no_file_selected');
    break;
    default :   $this->set_error('upload_no_file_selected');
    break;
    } return FALSE;
    }
      

  7.   


    // Set the uploaded data as class variables
    $this->file_temp = $_FILES[$field]['tmp_name'];
    $this->file_name = $_FILES[$field]['name'];
    $this->file_size = $_FILES[$field]['size'];
    $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']);
    $this->file_type = strtolower($this->file_type);
    $this->file_ext  = $this->get_extension($_FILES[$field]['name']);

    // Convert the file size to kilobytes
    if ($this->file_size > 0)
    {
    $this->file_size = round($this->file_size/1024, 2);
    } // Is the file type allowed to be uploaded?
    if ( ! $this->is_allowed_filetype())
    {
    $this->set_error('upload_invalid_filetype');
    return FALSE;
    } // Is the file size within the allowed maximum?
    if ( ! $this->is_allowed_filesize())
    {
    $this->set_error('upload_invalid_filesize');
    return FALSE;
    } // Are the image dimensions within the allowed size?
    // Note: This can fail if the server has an open_basdir restriction.
    if ( ! $this->is_allowed_dimensions())
    {
    $this->set_error('upload_invalid_dimensions');
    return FALSE;
    } // Sanitize the file name for security
    $this->file_name = $this->clean_file_name($this->file_name); // Remove white spaces in the name
    if ($this->remove_spaces == TRUE)
    {
    $this->file_name = preg_replace("/\s+/", "_", $this->file_name);
    } /*
     * Validate the file name
     * This function appends an number onto the end of
     * the file if one with the same name already exists.
     * If it returns false there was a problem.
     */
    $this->orig_name = $this->file_name; if ($this->overwrite == FALSE)
    {
    $this->file_name = $this->set_filename($this->upload_path, $this->file_name);

    if ($this->file_name === FALSE)
    {
    return FALSE;
    }
    } /*
     * Move the file to the final destination
     * To deal with different server configurations
     * we'll attempt to use copy() first.  If that fails
     * we'll use move_uploaded_file().  One of the two should
     * reliably work in most environments
     */
    if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name))
    {
    if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name))
    {
     $this->set_error('upload_destination_error');
     return FALSE;
    }
    }

    /*
     * Run the file through the XSS hacking filter
     * This helps prevent malicious code from being
     * embedded within a file.  Scripts can easily
     * be disguised as images or other file types.
     */
    if ($this->xss_clean == TRUE)
    {
    $this->do_xss_clean();
    } /*
     * Set the finalized image dimensions
     * This sets the image width/height (assuming the
     * file was an image).  We use this information
     * in the "data" function.
     */
    $this->set_image_properties($this->upload_path.$this->file_name); return TRUE;
    }

    // --------------------------------------------------------------------

    /**
     * Finalized Data Array
     *
     * Returns an associative array containing all of the information
     * related to the upload, allowing the developer easy access in one array.
     *
     * @access public
     * @return array
     */
    function data()
    {
    return array (
    'file_name' => $this->file_name,
    'file_type' => $this->file_type,
    'file_path' => $this->upload_path,
    'full_path' => $this->upload_path.$this->file_name,
    'raw_name' => str_replace($this->file_ext, '', $this->file_name),
    'orig_name' => $this->orig_name,
    'file_ext' => $this->file_ext,
    'file_size' => $this->file_size,
    'is_image' => $this->is_image(),
    'image_width' => $this->image_width,
    'image_height' => $this->image_height,
    'image_type' => $this->image_type,
    'image_size_str' => $this->image_size_str,
    );
    }

    // --------------------------------------------------------------------

    /**
     * Set Upload Path
     *
     * @access public
     * @param string
     * @return void
     */
    function set_upload_path($path)
    {
    $this->upload_path = $path;
    }

    // --------------------------------------------------------------------

    /**
     * Set the file name
     *
     * This function takes a filename/path as input and looks for the
     * existence of a file with the same name. If found, it will append a
     * number to the end of the filename to avoid overwriting a pre-existing file.
     *
     * @access public
     * @param string
     * @param string
     * @return string
     */
    function set_filename($path, $filename)
    {
    if ($this->encrypt_name == TRUE)
    {
    mt_srand();
    $filename = md5(uniqid(mt_rand())).$this->file_ext; 
    }

    if ( ! file_exists($path.$filename))
    {
    return $filename;
    }

    $filename = str_replace($this->file_ext, '', $filename);

    $new_filename = '';
    for ($i = 1; $i < 100; $i++)
    {
    if ( ! file_exists($path.$filename.$i.$this->file_ext))
    {
    $new_filename = $filename.$i.$this->file_ext;
    break;
    }
    } if ($new_filename == '')
    {
    $this->set_error('upload_bad_filename');
    return FALSE;
    }
    else
    {
    return $new_filename;
    }
    }

    // --------------------------------------------------------------------

    /**
     * Set Maximum File Size
     *
     * @access public
     * @param integer
     * @return void
     */
    function set_max_filesize($n)
    {
    $this->max_size = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n;
    }

    // --------------------------------------------------------------------

    /**
     * Set Maximum Image Width
     *
     * @access public
     * @param integer
     * @return void
     */
    function set_max_width($n)
    {
    $this->max_width = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n;
    }

    // --------------------------------------------------------------------

    /**
     * Set Maximum Image Height
     *
     * @access public
     * @param integer
     * @return void
     */
    function set_max_height($n)
    {
    $this->max_height = ( ! eregi("^[[:digit:]]+$", $n)) ? 0 : $n;
    }

    // --------------------------------------------------------------------

    /**
     * Set Allowed File Types
     *
     * @access public
     * @param string
     * @return void
     */
    function set_allowed_types($types)
    {
    $this->allowed_types = explode('|', $types);
    }

    // --------------------------------------------------------------------

    /**
     * Set Image Properties
     *
     * Uses GD to determine the width/height/type of image
     *
     * @access public
     * @param string
     * @return void
     */
    function set_image_properties($path = '')
    {
    if ( ! $this->is_image())
    {
    return;
    } if (function_exists('getimagesize'))
    {
    if (FALSE !== ($D = @getimagesize($path)))
    {
    $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $this->image_width = $D['0'];
    $this->image_height = $D['1'];
    $this->image_type = ( ! isset($types[$D['2']])) ? 'unknown' : $types[$D['2']];
    $this->image_size_str = $D['3'];  // string containing height and width
    }
    }
    }

    // --------------------------------------------------------------------

    /**
     * Set XSS Clean
     *
     * Enables the XSS flag so that the file that was uploaded
     * will be run through the XSS filter.
     *
     * @access public
     * @param bool
     * @return void
     */
    function set_xss_clean($flag = FALSE)
    {
    $this->xss_clean = ($flag == TRUE) ? TRUE : FALSE;
    }
      

  8.   

    没那么复杂的
    打开数据库后,先执行这一条SQL命令就可以了.
    names("utf-8")
      

  9.   

    你那还好,,我这里,数据库们问题,不乱码,但是,每次上传“中文名字的图片”时,就报错,但数据库里没有任何问题。Warning: move_uploaded_file(picture/2未命名.jpg) [function.move-uploaded-file]: failed to open stream: Invalid argument in D:\wamp\www\xiangmu\guanliyuan\photo1.php on line 21
     
    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\wamp\tmp\phpE26.tmp' to 'picture/2未命名.jpg' in D:\wamp\www\xiangmu\guanliyuan\photo1.php on line 21
     提交成功。
    明明已经上传了,还是会出错。请教高明
      

  10.   

    补充楼上的,,数据库没任何问题,但是不能把,图片移动到制定文件夹《《《我用的dreamweaver中文不被允许,我应该怎么配置一下?,,