如何获取上传文件的文件类型?如果它是.ppt
,.docx
,.pdf
,.png
, .mp4
等。有人可以帮助我吗?我开始学习文件上传。请给我一些线索。只是一个新手到PHP。如何获取上传文件的文件扩展名
这是我的代码。
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-upload']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$folder="uploads/";
// new file size in KB
$new_size = $file_size/1024;
// new file size in KB
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(file,size) VALUES('$final_file','$new_size')";
mysql_query($sql);
?>
<script>
alert('successfully uploaded');
window.location.href='index.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='index.php?fail';
</script>
<?php
}
}
?>
试试这个: $ _FILES ['file'] ['type']; –
快,大家上传一个名为“',0)的文件; drop table tbl_uploads; - ”! –
它返回像这样的'application/vnd.openxmlformats-officedocument.wordprocessingml.document'这么长的数据。我怎样才能使它具体像'.docx'? – nethken