开发者社区> 问答> 正文

请教个PHP文件中文名乱码的问题?报错

<?php # Script 11.2 - images.php
// This script lists the images in the uploads directory.

$dir = 'uploads'; // Define the directory to view.

$files = scandir($dir); // Read all the images into an array.

// Display each image caption as a link to the JavaScript function.
foreach ($files as $image) {

	if (substr($image, 0, 1) != '.') { // Ignore anything starting with a period.
	
		// Get the image's size in pixels.
		$image_size = getimagesize ("$dir/$image");
		
		// Calculate the image's size in kilobytes.
		$file_size = round ( (filesize ("$dir/$image")) / 1024) . "kb";
		
		
		
		// Print the information.
		echo "  <tr>
			<td><a
			<td>$file_size</td>
		</tr>";
	
	} // End of the IF.
    
} // End of the foreach loop.



新手遇到个问题,之前关于上传文件中文名乱码的,用了iconv('utf-8', 'gb2312', $_FILES['upload']['name'])解决了,现在想要把之前上传的图片文件都列出来,又遇到这个问题了。

现在我想要显示上传后图片的信息, 效果是下面这样的

请问 文件名$image 以及连接的url  乱码问题 ,代码那块应该怎么修改下。 小弟在这里先谢谢大家。

我这样改报错说iconv(): Detected an illegal character in input string in

// Print the information.
		echo "  <tr>
			<td><a 'gb2312', $image)."</a></td>
			<td>$file_size</td>
		</tr>";


搜了下,用mb_convert_encoding这个解决了,但是还是想知道iconv怎么解决?


展开
收起
爱吃鱼的程序员 2020-06-20 19:17:01 599 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    统一编码!

    php脚本、html页面、数据库统一为UTF8,就没这么多烦恼了。

    2020-06-20 19:17:17
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载