文件上传编码问题
用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倒还乱码了。呵呵。

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


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

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
