【发布时间】:2016-09-19 15:56:53
【问题描述】:
我正在尝试为前端的 wordpress 用户上传头像图像。我正在使用此代码
$files = $_FILES['post_files'];
foreach($files as $file){
if(is_array($file)){
$uploaded_file_type = $file['type'];
$allowed_file_types = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif');
if(!in_array($uploaded_file_type, $allowed_file_types)) {
$errors['image_empty'] = __( 'this image is not valid', 'themename' );
}
}
}
不允许上传 php 文件,但如果他们将 php 文件扩展名更改为 png 或 jpeg,他们可以将 php 文件上传到我的服务器。我尝试使用getimagesize(),但我不能,我是 php 的新手。或者有没有其他解决方案?
感谢回答
【问题讨论】:
-
为什么需要检查这个?如果他们将 PHP 文件作为图像上传,最糟糕的情况是图像不会显示 - 您的服务器不会在其中运行 PHP(除非配置真的很糟糕:))。
-
我正在使用dreamhost,如果我可以上传shell.php,我可以访问所有文件并可以编辑
-
如果它没有 .php 扩展名则不会...
标签: php wordpress image upload