这是我的第一个问题。我是PHP的新手,但我一直在寻找这个问题的答案大约一个小时,并且没有运气。也许我只是没有正确阅读,但我希望你们能帮助我。 我想让人们只将一种文件类型上传到我的网站。该文件类型是.osk。我不确定我是否正确地做了这个,但我把它设置得像这样
$types = array ('application/osk');
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$target_path = "skins/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path, $types)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
每当我提交特定文件类型时,我都会收到错误消息。如果我提交任何其他内容,我也会收到错误,但这是预料之中的。 对不起,如果代码一团糟。正如我之前所说,我是新手。但是,如果有人能帮助我弄清楚这一点,我会很高兴。
答案 0 :(得分:0)
试试此代码
$file_parts = pathinfo($_FILES['uploadedfile']['name']);
// Check file is osk
if($file_parts['extension'] == 'osk')
{
// move file
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path))
{
echo "Uploaded";
}
else
{
echo "File was not uploaded";
}
}