高手进,php上传文件乱码问题
用php写的文件上传代码,可是上传在指定目录里的文件的文件名是乱码~~<?php/*****************************************...
用php写的文件上传代码,可是上传在指定目录里的文件的文件名是乱码~~ <?php/****************************************************$max_file_size : 上传文件大小限制, 单位BYTE$destination_folder : 上传文件路径****************************************************/$uptypes=array("application/msword","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-publisher","application/vnd.ms-powerpoint","application/vnd.ms-excel");//上传文件类型列表$destination_folder="file/"; //上传文件路径?> <form enctype="multipart/form-data" method="post" name="upform"> <table> <tr> <td height="30">上传文档:</td> </tr> <tr> <td height="30"><input name="upfile" type="file" class="file_submit"></td> </tr> <tr> <td>允许上传的文件类型: doc, xls, ppt, docx, xlsx, pptx</td> </tr> <tr> <td><input type="submit" value="上 传" class="picturesubmit_botton"></td> </tr> </table> </form> <?phpif ($_SERVER['REQUEST_METHOD'] == 'POST') {?> <div class="picturemessage"> <?php if(!is_uploaded_file($_FILES['upfile'][tmp_name])) //是否存在文件 { echo "文件大小请不要超过4M!"; }else{ $file = $_FILES['upfile']; if(!in_array($file['type'], $uptypes)) //检查文件类型 { echo "文件类型不符!".$file['type']; }else{ if(!file_exists($destination_folder)) { mkdir($destination_folder); } $filename=$file['tmp_name']; $image_size = getimagesize($filename); $thefilename= $file['name']; $destination = $destination_folder.$thefilename; if (file_exists($destination) && $overwrite != true) { echo "<font color=red>同名文件已经存在了</font>"; }else{ if(!move_uploaded_file ($filename, $destination)) { echo "<font color=red>移动文件出错!</font>"; }else{ date_default_timezone_set('Asia/Shanghai');$date=date("Y-m-d H:i:s"); $author=$teamname[$team-1]; $input="INSERT INTO `article_menu` ( `num` , `title` , `author` , `article` , `date` , `picture` , `team` , `key` , `clicknum` ) VALUES (NULL , '$thefilename', '$author', '', '$date', '0', '$team', '5', '0')";$response=mysql_query($input); $change=mysql_query("UPDATE `order` SET `num` = num+1 WHERE `order`.`team` =$team LIMIT 1"); mysql_close($select); echo "<font color=red>已经成功上传</font><br>文件名:<font color=blue><a href=\"".$destination_folder.$fname."\">".$fname."</a></font><br>"; echo "大小:".$file['size']." bytes";}}}}?> </div> <?php}?>
展开
3个回答
展开全部
代码也太乱了吧?看的我头晕……闪人。
给你贴段代码吧。
<?php
if(isset($_FILES['file'])){
$upload='upload/'.$_FILES['file']['name'];
if(is_uploaded_file($_FILES['file']['tmp_name'])){
//iconv函数解决上传文件中文名乱码的问题,但是不提倡文件名是中文的,特别是unix/linux环境下
if(!move_uploaded_file($_FILES['file']['tmp_name'],iconv('UTF-8','gb2312',$upload))){
echo 'failed';
}else{
echo 'success';
}
}
else{
echo 'failed';
}
}
?>
给你贴段代码吧。
<?php
if(isset($_FILES['file'])){
$upload='upload/'.$_FILES['file']['name'];
if(is_uploaded_file($_FILES['file']['tmp_name'])){
//iconv函数解决上传文件中文名乱码的问题,但是不提倡文件名是中文的,特别是unix/linux环境下
if(!move_uploaded_file($_FILES['file']['tmp_name'],iconv('UTF-8','gb2312',$upload))){
echo 'failed';
}else{
echo 'success';
}
}
else{
echo 'failed';
}
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询