dongyu9850 2013-05-13 10:16
浏览 34
已采纳

UTF8变量从FLASH发布到文件名

I am using a script to send a "$filename" variable from flash to PHP in order to create an xml file. The problem is that when I am typing Greek Characters as Filename the filename on the server gets values such as these for example: (δσωδσαωςεωςεβ.qxml)

I do not have any problem a) When writing english characters, b) When writing greek characters data in the xml file.

I am using file_put_contents function.

If instead of getting the Post variable as filename, I set my own filename such as "Ελληνικά.qxml" it works without a problem.

Thanks a lot in advance.

$string = $_POST['xmldata'];
$filename = $_POST['filename'];

$path = "test/";

//$dir_handle = @opendir($path) or mkdir("{$path}", 0777, true);

file_put_contents($path."/".$filename."", $string);

This problem was solved, but another arose. When I try to open the file from flash it does not recognise it now because it is in Greek.

  • 写回答

1条回答 默认 最新

  • duanhai7274 2013-05-13 10:20
    关注

    The problem is that flash is sending the data in different encoding. From the comments in the PHP manual for mb_convert_encoding I can see that you should use the following to get it to work (tested on danisch charactors and not greek)

    <?php
    $string = isset($_POST['xmldata'])?$_POST['xmldata']:"";
    $filename = isset($_POST['filename'])?$_POST['filename']:"";
    
    //tested on danish chars
    /*
    $string = mb_convert_encoding($string, "ISO-8859-1", "UTF-8");
    $filename = mb_convert_encoding($filename, "ISO-8859-1", "UTF-8");
    */
    
    //tested on greek chars
    $string = mb_convert_encoding($string, "ISO-8859-7", "UTF-8");
    $filename = mb_convert_encoding($filename, "ISO-8859-7", "UTF-8");
    
    $path = "test/";
    
    //$dir_handle = @opendir($path) or mkdir("{$path}", 0777, true);
    
    file_put_contents($path."/".$filename."", $string);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"
  • ¥20 基于决策树的数字信号处理,2ask 2psk 2fsk的代码,检查下报错的原因
  • ¥20 python作业求过程
  • ¥15 wincc已组态的变量过多
  • ¥60 如图:直线与椭圆X轴平行,求直线与椭圆任意一点的相切坐标计算公式
  • ¥50 如何用python使用opencv里的cv::cudacodec::VideoWriter函数对视频进行GPU硬编码
  • ¥100 c#solidworks 二次开发 工程图自动标边线法兰 等折弯尺寸怎么标
  • ¥15 halcon DrawRegion 提示错误
  • ¥15 FastAPI Uvicorn启动显示404
  • ¥15 centos7.9脚本,怎么排除特定的访问记录