文件上传编码有关问题
文件上传编码问题
用Flash+PHP实现文件的批量上传。PHP在保存文件时,遇到编码问题:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php header("Content-Type:text/html;charset=utf-8"); function createDir($path){ if (!file_exists($path)){ createDir(dirname($path)); mkdir($path, 0777); } } $uploaddir='upfile/'.date('Ymd').'/'; createDir($uploaddir); $uploadfile=$uploaddir.iconv('utf-8','gbk',$_POST['fn']); if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadfile)) { echo 'OK'.$_POST['bn'].'{[(*})]'.$_POST['up'].'{[(*})]'.'$uploadjson'.'{[(*})]'.'$listjson'; }else{ echo 'ERROR'; }?>
文件名很不规范,有中文、英文、法文、俄文、……不确定类型,这时候有些文件保存下来,要么是乱码,要么被截断(扩展名都丢失了)。iconv('utf-8','gbk',$_POST['fn']),这里的问题?该如何做?
------解决方案--------------------
你当前页面用了utf-8
header("Content-Type:text/html;charset=utf-8");
而这个应不该转成gbk
$uploadfile=$uploaddir.iconv('utf-8','gbk',$_POST['fn']);
去掉或是
$uploadfile=$uploaddir.iconv('gbk','utf-8', $_POST['fn']);
试试
------解决方案--------------------
GBK编码的字符串没有俄文这些符号。也就是说它只适用于中文
建议你用utf-8来保存,文件名乱码的问题就这么撂着吧
------解决方案--------------------
$uploadfile = $uploaddir . base64_encode($_POST['fn']) . '.' . pathinfo($_POST'fn'], PATHINFO_EXTENSION);
------解决方案--------------------
你数据源是GBK要怎子搞呢。
iconv用//IGNORE忽略特殊符号转成UTF8、要么就重命名。
------解决方案--------------------
你自己在你的windows机上能够输入俄文,阿拉伯文命名一个文件吗?
文件名要视乎客户操作系统的编码,一般国内用户用的都是中文版windows,系统默认内部编码属GBK,GBK怎么可能包含俄文之类的语种呢。或者换过来说你让操作系统编码为iso-8859-1的用户下载你的中文名文件,中文即使给你转成gbk还不一样乱码。干脆就随机命名好了,不然有啥好方法,全世界各地不同的操作系统用户系统编码千差万别,除非所有都统一用utf-8做内码,你这边也不用费劲用iconv转了。
你看我现在用ubuntu,系统编码就是utf-8的,那些中文俄文法文你不转GBK对我这种用户就算正常的,你转GBK倒还乱码了。呵呵。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Go language encoding analysis: UTF-8 and GBK comparison In the Go language, processing string encoding is one of the common tasks. Among them, UTF-8 and GBK are two commonly used character encoding methods. This article will conduct a detailed comparison between UTF-8 and GBK, discuss their differences and usage, and attach specific code examples. 1. Introduction to UTF-8 and GBK UTF-8: UTF-8 is a variable-length Unicode encoding method that can represent characters in almost all languages in the world. UTF-8

For PHP developers, using POST to jump to pages with parameters is a basic skill. POST is a method of sending data in HTTP. It can submit data to the server through HTTP requests. The jump page processes and jumps the page on the server side. In actual development, we often need to use POST with parameters to jump to pages to achieve certain functional purposes.

Python simulates the browser sending post requests importrequests format request.postrequest.post(url,data,json,kwargs)#post request format request.get(url,params,kwargs)#Compared with get request, sending post request parameters are divided into forms ( x-www-form-urlencoded) json (application/json) data parameter supports dictionary format and string format. The dictionary format uses the json.dumps() method to convert the data into a legal json format string. This method requires

PHP is a widely used server-side scripting language that can be used to create interactive and dynamic web applications. When developing PHP applications, we usually need to submit user input data to the server for processing through forms. However, sometimes we need to determine whether form data has been submitted in PHP. This article will introduce how to make such a determination.

1. Java calls post interface 1. Use URLConnection or HttpURLConnection that comes with java. There is no need to download other jar packages. Call URLConnection. If the interface response code is modified by the server, the return message cannot be received. It can only be received when the response code is correct. to return publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt

实现如下:server{listen80;listen443ssl;server_namenirvana.test-a.gogen;ssl_certificate/etc/nginx/ssl/nirvana.test-a.gogen.crt;ssl_certificate_key/etc/nginx/ssl/nirvana.test-a.gogen.key;proxy_connect_timeout600;proxy_read_timeout600;proxy_send_timeout600;c

PHP is a programming language widely used in website development, and page jumps and carrying POST data are common requirements in website development. This article will introduce how to implement PHP page jump and carry POST data, including specific code examples. In PHP, page jumps are generally implemented through the header function. If you need to carry POST data during the jump process, you can do it through the following steps: First, create a page containing a form, where the user fills in the information and clicks the submit button. Acti in the form

Title: PHP code example: How to use POST to pass parameters and implement page jumps In web development, it often involves the need to pass parameters through POST and process them on the server side to implement page jumps. PHP, as a popular server-side scripting language, provides a wealth of functions and syntax to achieve this purpose. The following will introduce how to use PHP to implement this function through a practical example. First, we need to prepare two pages, one to receive POST requests and process parameters
